Skip to content

Commit 0b88b5a

Browse files
committed
📝 README and description
1 parent 507f8c1 commit 0b88b5a

File tree

2 files changed

+182
-0
lines changed

2 files changed

+182
-0
lines changed

README.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Discord-Module-Loader [![Version](https://img.shields.io/npm/v/discord-module-loader.svg)](https://www.npmjs.com/package/discord-module-loader)
2+
3+
A package that lets you load events and commands easily and fast.
4+
Automatically update the commands on the Discord API just by running a function!
5+
6+
## Instalation
7+
8+
```bash
9+
# npm
10+
npm install discord-module-loader
11+
12+
# yarn
13+
yarn add discord-module-loader
14+
```
15+
16+
## Usage
17+
18+
### Importing
19+
20+
#### TypeScript
21+
22+
```ts
23+
// Here we're importing the default export "ModuleLoader", which is the main class which will load all modules
24+
// as well as the DiscordEvent class which is used to add event listeners to the main class
25+
import ModuleLoader, { DiscordEvent } from "discord-module-loader";
26+
```
27+
28+
#### JavaScript
29+
30+
```js
31+
// Here we're importing the default export "ModuleLoader", which is the main class which will load all modules
32+
// as well as the DiscordEvent class which is used to add event listeners to the main class
33+
const { DiscordEvent, default: ModuleLoader } = require("discord-module-loader");
34+
```
35+
36+
Or, if you only want the main class ModuleLoader
37+
38+
```js
39+
const ModuleLoader = require("discord-module-loader");
40+
```
41+
42+
Or if you only want the event class
43+
44+
```js
45+
const { DiscordEvent } = require("discord-module-loader");
46+
```
47+
48+
### Using our module loader
49+
To use the ModuleLoader, your bot has to use the following file structure:
50+
51+
```
52+
53+
├─ commands
54+
├─ events
55+
├─ guilds
56+
├─ modules
57+
╰─ index
58+
```
59+
60+
#### `commands` folder
61+
Inside of the `commands` folder you can put as many command files as you want!
62+
We suggest you put the command name as the file name, but it is not required.
63+
In those files the following must be exported:
64+
```js
65+
import { DiscordCommand } from "discord-module-loader";
66+
67+
export default new DiscordCommand({
68+
name: "name",
69+
description: "Example command",
70+
execute: async (int) => {
71+
console.log(int);
72+
}
73+
})
74+
```
75+
In the `DiscordCommand` class you have to pass an object with the following arguments:
76+
77+
| Argument | Description | Required | Type |
78+
|---|---|---|---|
79+
| `name` | Name of the command | Yes | `string` |
80+
| `description` | Description of the command | Yes | `string` |
81+
| `defaultPermission` | Whether the command is enabled by default when the app is added to a guild | No | `boolean` |
82+
| `options` | The options of the command | No | [`ApplicationCommandOptionData`](https://discord.js.org/#/docs/discord.js/stable/typedef/ApplicationCommandOptionData)`[]` |
83+
| `cooldown` | The amount of time in seconds a user has to wait between command executions | No | `number` |
84+
| `channelAllowlist` | Array of Discord channel ids where the command is allowed to be executed in | No | `string[]` |
85+
| `channelDenylist` | Array of Discord channel ids where the command is not allowed to be executed in | No | `string[]` |
86+
| `permissions` | Permission data of the command | No | [`ApplicationCommandPermissionData`](https://discord.js.org/#/docs/discord.js/stable/typedef/ApplicationCommandPermissionData)`[]` |
87+
| `hasUserCommand` | Whether the command has a user context menu | No | `boolean` |
88+
| `execute` | The function which will be run when the command is executed | Yes | `Function (interaction:`[`CommandInteraction`](https://discord.js.org/#/docs/discord.js/stable/class/CommandInteraction)`)` |
89+
90+
#### `events` folder
91+
Inside of the `events` folder you can put as many event files as you want!
92+
We suggest you put the event name as the file name, but it is not required.
93+
In those files the following must be exported:
94+
```ts
95+
import { DiscordEvent } from "discord-module-loader";
96+
97+
export default new DiscordEvent("messageCreate", message => {
98+
console.log(message.content);
99+
});
100+
```
101+
`"messageCreate"` can be changed for any event name just like the `message` variable can be changed to the incoming data of the event.
102+
103+
#### `modules` folder
104+
To use the `DiscordModule` class you have to use the following file structure:
105+
106+
```
107+
● (modules folder)
108+
╰─ <module name>
109+
├─ commands
110+
├─ events
111+
├─ modules
112+
╰─ index
113+
```
114+
The commands, events, and modules folders are just like their above specified ones.
115+
In the index file the following must be exported:
116+
```ts
117+
import { DiscordModule } from "discord-module-loader";
118+
119+
export default new DiscordModule("<module name>");
120+
```
121+
122+
In the `DiscordModule` class you only have to specify the name you want the module to have.
123+
124+
#### `guilds` folder
125+
To use the `DiscordGuild` class you have to use the following file structure:
126+
127+
```
128+
● (guilds folder)
129+
╰─ <guild name>
130+
├─ commands
131+
├─ events
132+
├─ modules
133+
╰─ index
134+
```
135+
136+
The commands, events, and modules folders are just like their above specified ones.
137+
But the index one is of course a lil' different! In the index file the following must be exported:
138+
```ts
139+
import { DiscordGuild } from "discord-module-loader";
140+
141+
export default new DiscordGuild("<guildId>");
142+
```
143+
144+
In the `DiscordGuild` class you only have the specify the guildId wherein the commands, events, and modules should work.
145+
146+
#### `index` file
147+
```js
148+
// Firstly we must create the normal Discord Client from Discord.js
149+
const client = new Client({ intents: [Intents.Flags.GUILD, Intents.Flags.GUILD_MESSAGES] });
150+
151+
// Afterwards we can initialize the module loader with the Discord.js Client
152+
// a few options could be appended after the client, more information about the ModuleLoader options can be found further below
153+
const moduleLoader = new ModuleLoader(client);
154+
155+
// Now we can login and load all the modules
156+
// inside of the load functions you can also input a string argument for a different file directory if you didn't follow above mentioned file structure
157+
// you can now also update all slash commands on the Discord API by just running the updateSlashCommands function
158+
client.login(process.env.TOKEN);
159+
client.on("ready", async () => {
160+
await moduleLoader.loadAll();
161+
await moduleLoader.updateSlashCommands();
162+
});
163+
```
164+
165+
In the `ModuleLoader` class you can pass an object with the following arguments:
166+
(All arguments are optional)
167+
168+
| Argument | Description | Type | Default Value |
169+
|---|---|---|---|
170+
| `unknownCommandMessage` | The message shown when a user executes an unknown command | `string` | Couldn't find executed command. Please try again later, or report the issue. |
171+
| `disabledCommandMessage` | The message shown when a user executes a disabled command | `string` | This command is currently disabled. Please try again later. |
172+
| `disallowedChannelMessage` | The message shown when a user executes a command in a disallowed channel | `string` | You're not allowed to execute this command in this channel! |
173+
| `commandCooldownMessage` | The message shown when a user executes a command while on cooldown | `string` | Please wait % seconds before using this command again. |
174+
175+
## Contributing
176+
177+
Due to Discord and Discord.js always updating, it is possible some things might break. If you believe you have found and issue, feel free to [open a pull request](https://github.com/Recodive/Discord-Module-Loader/compare).
178+
179+
## Inspiration
180+
181+
Due to the amount of Discord bots our team makes it was always annoying to copy over our module loader and getting it working for that project, hence why we decided to just make one module loader which we can import into all of our Discord Bot projcets. We hope to keep this module updated and working whenever new features are added to Discord/Discord.js, but we may also add custom things to our likings. This package was created by [Bas950](https://github.com/Bas950) and [Timeraa](https://github.com/Timeraa) and is not officially endorsed by Discord nor affiliated with the company in any way.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "discord-module-loader",
3+
"description": "A package that lets you load events and commands easily and fast.",
34
"version": "1.0.0",
45
"main": "lib/index.js",
56
"repository": "https://github.com/Recodive/Discord-Module-Loader",

0 commit comments

Comments
 (0)