|
1 | 1 | # DiscordJS Bot Template |
| 2 | + |
| 3 | +> Updated to discord.js v14.11.0 |
| 4 | +
|
| 5 | +## About |
| 6 | + |
| 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 | + |
| 9 | +## Setup |
| 10 | + |
| 11 | +1. Clone the repository |
| 12 | +2. Run `yarn` to install dependencies |
| 13 | +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 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +### Add Slash commands |
| 21 | + |
| 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) |
| 24 | + |
| 25 | +The command will be automatically registered when the bot starts. |
| 26 | + |
| 27 | +### Events |
| 28 | + |
| 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. |
| 30 | + |
| 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) | |
| 35 | + |
| 36 | +See the [DiscordJS documentation](https://old.discordjs.dev/#/docs/discord.js/main/typedef/Events) for a list of events. |
| 37 | + |
| 38 | +### Commands JSON file |
| 39 | + |
| 40 | +The `config/slashCommands.json` file is used to configure the active slash commands. |
| 41 | + |
| 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). |
| 43 | + |
| 44 | +### Properties |
| 45 | + |
| 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. | |
| 54 | + |
| 55 | +#### Options |
| 56 | + |
| 57 | +The list of options for this command. |
| 58 | + |
| 59 | +| Property | Type | Required | Description | Valid in Types | |
| 60 | +| ----------- | ---------------- | -------- | --------------------------------------------------------- | ----------------------------- | |
| 61 | +| name | `string` | Yes | The name of the option. | All | |
| 62 | +| description | `string` | Yes | The description of the option. | All | |
| 63 | +| type | `string` | Yes | The type of the option. See [Option Types](#option-types) | All | |
| 64 | +| required | `boolean` | No | Whether this option is required or not (Default: false). | All | |
| 65 | +| choices | `Array<Choices>` | No | The list of choices for this option. | `INTEGER \| NUMBER \| STRING` | |
| 66 | +| minValue | `number` | No | The minimum value of the option. | `INTEGER \| NUMBER` | |
| 67 | +| maxValue | `number` | No | The maximum value of the option. | `INTEGER \| NUMBER` | |
| 68 | + |
| 69 | +##### Choice Properties |
| 70 | + |
| 71 | +The properties of each choice within the `choices` array. |
| 72 | + |
| 73 | +| Property | Type | Description | |
| 74 | +| -------- | ------------------ | ----------------------------------------------------------------------------------- | |
| 75 | +| name | `string` | The name of the choice. | |
| 76 | +| value | `string \| number` | The value of the choice (the available value is based on the off the option value). | |
| 77 | + |
| 78 | +#### Option Types |
| 79 | + |
| 80 | +For further information on option types, see the [Discord documentation](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-type). |
| 81 | + |
| 82 | +| Type | Description | |
| 83 | +| ------------- | -------------------------------- | |
| 84 | +| `STRING` | Represents a string value. | |
| 85 | +| `BOOLEAN` | Represents a boolean value. | |
| 86 | +| `NUMBER` | Represents a numeric value. | |
| 87 | +| `INTEGER` | Represents an integer value. | |
| 88 | +| `ROLE` | Represents a role. | |
| 89 | +| `USER` | Represents a user. | |
| 90 | +| `CHANNEL` | Represents a channel. | |
| 91 | +| `MENTIONABLE` | Represents a mentionable entity. | |
| 92 | +| `ATTACHMENT` | Represents an attachment. | |
| 93 | + |
| 94 | +## Contributing |
| 95 | + |
| 96 | +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. |
| 97 | + |
| 98 | +## License |
| 99 | + |
| 100 | +[ISC](https://choosealicense.com/licenses/isc/) |
0 commit comments