This is a template for a Discord bot. It is written in JavaScript and uses the discord.js
library. It is designed to be easy to use and easy to modify.
Feature |
---|
✅ Very easy and simple |
✅ Supports most modern features such as slash commands, message components, modals... |
✅ Localization |
✅ Command Handler |
✅ Built-in commands |
✅ Error handler |
✅ Custom logger |
✅ Custom embeds |
- Clone this repository.
- Run
npm install
to install dependencies. - Rename the
.env.example
file to.env
and fill in the values. - Fill in the values in
config.json
. - Run
npm start
to start the bot.
- Create a new file in the
src/commands
directory. - Copy the following code into the file:
const { SlashCommandBuilder, ChatInputCommandInteraction } = require("discord.js");
module.exports = {
category: 'General', // The category the command belongs to. "Owner" and "Developer" are special categories. You can use anything as a category.
data: new SlashCommandBuilder() // The command data
.setName('command') // The name of the command
.setDescription('Command description'), // The description of the command
/**
* @param {ChatInputCommandInteraction} interaction
*/
async execute(interaction) {
interaction.reply('Hello, world!');
}
};
- Fill in the values in the code.
ping
: Replies with the bot's ping.help
: Replies with the help menu.eval
: Evaluates JavaScript code.
We use a custom embed class to make it easier to create embeds. It is similar to discord.js
's EmbedBuilder
but with default values. You can find the class in src/modules/embed.js
.
const EmbedMaker = require('../modules/embed.js');
const embed = new EmbedMaker(client) // You can use interaction.client in command files
.setTitle('Title')
.setDescription('Description')
- Find your language file in
src/i18n
and open it. If it doesn't exist, create it. - Copy the following code into the file:
module.exports = {
MY_LOCALIZED_TEXT: 'My localized text',
// ...
};
- Fill in the values in the code.
- Add your language to the
locales
object insrc/modules/localization.js
.
const { localize } = require('../modules/localization.js');
console.log(localize('en-US', 'MY_LOCALIZED_TEXT')); // Replace 'en-US' with the language code of your language file.
We use a custom logger class to make it easier to log messages. You can find the class in src/modules/logger.js
.
Method Usage: logger(type, title, ...messages)
const logger = require('../modules/logger.js');
logger('warning', 'COMMAND', 'Command', 'eval', 'blocked for', 'tolgchu', 'because it is developer only');
According to the above code, the logger will highlight "eval" and "tolgchu" parts.