|
1 | 1 | # DiscordJS Bot Template
|
2 | 2 |
|
3 |
| -> Updated to discord.js v14.11.0 |
| 3 | +> Updated to discord.js v14.14.1 |
4 | 4 |
|
5 | 5 | ## About
|
6 | 6 |
|
7 | 7 | This is a template for a DiscordJS v14 bot. It is written in TypeScript and uses [DiscordJS](https://discord.js.org/#/) as the library for interacting with Discord.
|
8 | 8 |
|
9 | 9 | ## Setup
|
10 | 10 |
|
| 11 | +> **Note** |
| 12 | +> This project uses [pnpm](https://pnpm.io/) as the package manager. You can use `npm` or `yarn` if you prefer. |
| 13 | +
|
11 | 14 | 1. Clone the repository
|
12 |
| -2. Run `yarn` to install dependencies |
| 15 | +2. Run `pnpm i` to install dependencies |
13 | 16 | 3. Copy `.env.example` to `.env` and fill in the values
|
14 |
| -4. Run `yarn dev` to start the bot in development mode |
15 |
| -5. Run `yarn build` to build the bot |
16 |
| -6. Run `yarn start` to start the bot in production mode |
| 17 | +4. Run `pnpm dev` to start the bot in development mode |
| 18 | +5. Run `pnpm build` to build the bot |
| 19 | +6. Run `pnpm start` to start the bot in production mode |
17 | 20 |
|
18 | 21 | ## Usage
|
19 | 22 |
|
20 | 23 | ### Add Slash commands
|
21 | 24 |
|
22 |
| -1. Add your command in `config/slashCommands.json` |
23 |
| -2. Create a file in `src/commands/slash` with the same name as the command (in the relative subfolder if in a category) |
| 25 | +1. Create a `.ts` file in `src/commands/slash` with the same name as the command (in the relative subfolder if in a category) |
24 | 26 |
|
25 | 27 | The command will be automatically registered when the bot starts.
|
26 | 28 |
|
27 |
| -### Events |
| 29 | +### Creating a command file |
28 | 30 |
|
29 |
| -Events are automatically registered when the bot starts. To add an event, create a file in `src/events/<event_source>` with the name of the event and export default the event function. |
| 31 | +You can create a new command using `TypeScript`. |
30 | 32 |
|
31 |
| -| Event Source | Description | |
32 |
| -| ------------ | --------------------------------------------- | |
33 |
| -| `client` | Events emitted by the client (e.g. ready) | |
34 |
| -| `guild` | Events emitted by a guild (e.g. interactions) | |
| 33 | +The file must export the following object: |
35 | 34 |
|
36 |
| -See the [DiscordJS documentation](https://old.discordjs.dev/#/docs/discord.js/main/typedef/Events) for a list of events. |
| 35 | +```ts |
| 36 | +import { SlashCommand, SlashCommandConfig } from '@/types/command'; |
| 37 | + |
| 38 | +const config: SlashCommandConfig = { |
| 39 | + ... |
| 40 | +}; |
| 41 | + |
| 42 | +const command: SlashCommand = { |
| 43 | + ... |
| 44 | +}; |
| 45 | + |
| 46 | +export default { command, config }; |
| 47 | +``` |
| 48 | + |
| 49 | +> [!NOTE] |
| 50 | +> You can see all the types definition in `src/types/command.ts`. |
37 | 51 |
|
38 |
| -### Commands JSON file |
| 52 | +#### SlashCommandConfig |
39 | 53 |
|
40 |
| -The `config/slashCommands.json` file is used to configure the active slash commands. |
| 54 | +The `config` of the command contains all the information about the command that will be loaded. |
41 | 55 |
|
42 |
| -Is based of the schema `schemas/slash-commands.json` so you can use it to validate your JSON file (in VSCode the schema is automatically loaded). |
| 56 | +| Property | Type | Required | Description | |
| 57 | +| ----------- | ---------------- | -------- | --------------------------------------------------------------------- | |
| 58 | +| name | `string` | No | The name of the command. If not defined, the filename is used instead | |
| 59 | +| description | `string` | Yes | The description of the command. | |
| 60 | +| usage | `string` | No | The usage of the command. | |
| 61 | +| category | `string` | No | The category of the command. | |
| 62 | +| nsfw | `boolean` | No | Whether this command is NSFW or not (Default: false). | |
| 63 | +| options | `Array<Options>` | No | The list of options for this command. (see [](/#options)) | |
43 | 64 |
|
44 |
| -### Properties |
| 65 | +> [!IMPORTANT] |
| 66 | +> The `fileName` property is automatically added to the config object, DO NOT add it manually. |
45 | 67 |
|
46 |
| -| Property | Type | Required | Description | |
47 |
| -| ----------- | ---------------- | -------- | ------------------------------------------------------ | |
48 |
| -| name | `string` | Yes | The name of the command. | |
49 |
| -| description | `string` | Yes | The description of the command. | |
50 |
| -| usage | `string` | No | The usage of the command. | |
51 |
| -| category | `string` | No | The category of the command (matches the folder path). | |
52 |
| -| nsfw | `boolean` | No | Whether this command is NSFW or not (Default: false). | |
53 |
| -| options | `Array<Options>` | No | The list of options for this command. | |
| 68 | +#### SlashCommand |
| 69 | + |
| 70 | +The `command` object contains the function that will be executed when the command is called. |
| 71 | +It also contains the `permissions` for the command. (see [Permissions Guide](https://discordjs.guide/popular-topics/permissions.html#permissions)) |
54 | 72 |
|
55 | 73 | #### Options
|
56 | 74 |
|
@@ -91,6 +109,17 @@ For further information on option types, see the [Discord documentation](https:/
|
91 | 109 | | `MENTIONABLE` | Represents a mentionable entity. |
|
92 | 110 | | `ATTACHMENT` | Represents an attachment. |
|
93 | 111 |
|
| 112 | +### Events |
| 113 | + |
| 114 | +Events are automatically registered when the bot starts. To add an event, create a file in `src/events/<event_source>` with the name of the event and export default the event function. |
| 115 | + |
| 116 | +| Event Source | Description | |
| 117 | +| ------------ | --------------------------------------------- | |
| 118 | +| `client` | Events emitted by the client (e.g. ready) | |
| 119 | +| `guild` | Events emitted by a guild (e.g. interactions) | |
| 120 | + |
| 121 | +See the [DiscordJS documentation](https://old.discordjs.dev/#/docs/discord.js/main/typedef/Events) for a list of events. |
| 122 | + |
94 | 123 | ## Contributing
|
95 | 124 |
|
96 | 125 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
0 commit comments