Updated to discord.js v14.14.1
This is a template for a DiscordJS v14 bot. It is written in TypeScript and uses DiscordJS as the library for interacting with Discord.
Note This project uses pnpm as the package manager. You can use
npm
oryarn
if you prefer.
pnpm i
to install dependencies.env.example
to .env
and fill in the valuespnpm dev
to start the bot in development modepnpm build
to build the botpnpm start
to start the bot in production mode.ts
file in src/commands/slash
with the same name as the command (in the relative subfolder if in a category)The command will be automatically registered when the bot starts.
You can create a new command using TypeScript
.
The file must export the following object:
import { SlashCommand, SlashCommandConfig } from '@/types/command';
const config: SlashCommandConfig = {
...
};
const command: SlashCommand = {
...
};
export default { command, config };
[!NOTE] You can see all the types definition in
src/types/command.ts
.
The config
of the command contains all the information about the command that will be loaded.
[!IMPORTANT] The
fileName
property is automatically added to the config object, DO NOT add it manually.
The command
object contains the function that will be executed when the command is called.
It also contains the permissions
for the command. (see Permissions Guide)
The list of options for this command.
Property | Type | Required | Description | Valid in Types |
---|---|---|---|---|
name | string |
Yes | The name of the option. | All |
description | string |
Yes | The description of the option. | All |
type | string |
Yes | The type of the option. See Option Types | All |
required | boolean |
No | Whether this option is required or not (Default: false). | All |
choices | Array<Choices> |
No | The list of choices for this option. | INTEGER \| NUMBER \| STRING |
minValue | number |
No | The minimum value of the option. | INTEGER \| NUMBER |
maxValue | number |
No | The maximum value of the option. | INTEGER \| NUMBER |
The properties of each choice within the choices
array.
Property | Type | Description |
---|---|---|
name | string |
The name of the choice. |
value | string \| number |
The value of the choice (the available value is based on the off the option value). |
For further information on option types, see the Discord documentation.
Type | Description |
---|---|
STRING |
Represents a string value. |
BOOLEAN |
Represents a boolean value. |
NUMBER |
Represents a numeric value. |
INTEGER |
Represents an integer value. |
ROLE |
Represents a role. |
USER |
Represents a user. |
CHANNEL |
Represents a channel. |
MENTIONABLE |
Represents a mentionable entity. |
ATTACHMENT |
Represents an attachment. |
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.
Event Source | Description |
---|---|
client |
Events emitted by the client (e.g. ready) |
guild |
Events emitted by a guild (e.g. interactions) |
See the DiscordJS documentation for a list of events.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.