A multi-purpose discord.js v14 bot template. This is the successor of the djs-template repository.
- Slash Command Handler (global / guild)
- Context Menu Handler (global / guild)
- Interaction Handler (Message Components, Modals)
- Event Handler
- Sharding
- Localizations
- Customizable configuration
- Examples
Install the required npm modules.
npm installCreate a new file called .env in the root directory and insert your bot token as shown in the example.env file.
Apart from the token, the configuration takes place in the config.json file located in the src/ folder.
Specify a guild ID to which the guild commands will be deployed. Make sure that the bot is a member of this server and has sufficient permissions to create commands.
"guild": "your_guild_id"Choose if you want to receive message components and modals using the interaction handler.
"receiveMessageComponents": true,
"receiveModals": trueSelect whether to reply with a warning if an error occurs whilst executing an interaction.
"replyOnError": trueChoose whether you want to split the custom ID of an interaction by underscores (_). In this case, the interaction handler uses only the string before the first underscore (if any). This system makes sense if you want to use the custom ID to convey additional information.
For example report_527814442746904591 is treated as report.
"splitCustomId": falseIf you want to use global commands only, you can disable guild commands. The global attribute must still be true.
"useGuildCommands": trueDone! You can now experiment with some examples. For that, you just need to start your bot...
The bot can be started as a single instance or in processes intended for sharding. For smaller bots, the first variant should be sufficient.
To build & start the bot without sharding run
npm run start:botor just
npm run startTo build & start the sharding manager run
npm run start:managerDuring development, it is a good idea not to deploy all commands every time you restart. You can use the following command to disable automatic deployment and run the uncompiled bot / manager.
npm run dev:botnpm run dev:managerTo only compile a JavaScript build of your bot, run this command.
npm run buildThe finished build will be located in the dist/ directory.
This template contains some sample commands and interactions so you understand how to use it:
-
src/commands/example/ping.tsPing Command -
src/features/ping.tsPing Button Builder -
src/interactions/buttons/example/ping.tsPing Button Interaction -
src/context_menus/example/countCharacters.tsMessage Context Menu -
src/context_menus/example/displayAvatar.tsUser Context Menu
Hint: Commands, Context Menus and Interactions have to be located in a subfolder.
To make it easier to access the client's config and collections, the template includes the ExtendedClient class. It allows to access these properties directly from the client without importing them.
const client = new ExtendedClient();
const guildId = client.config.guild;However, the ExtendedClient cannot be accessed through an API object such as message or an interaction. The included handlers pass the _client as its own parameter, so you don't have to worry about that.
By default, this project supports translations. These are managed in the lang/ folder. The configuration is located in src/features/i18n.ts. Examples of usage can be found in the demo files.
This template is still under development and will be constantly extended, for example when changes are made to the Discord API.
