Basic discord bot template that supports slash commands, events and translations.
Discord.js v13 requires Node.js v16.6.0+ to run.
Install the dependencies.
npm install
Create .env
file in root directory.
TOKEN= // Bot token
CLIENT_ID= // Bot client id
GUILD_ID= // Test guild id
MONGO_PATH=mongodb://localhost:27017 // Path to mongo db.
Run the bot:
node index.js
Create new .js file in /commands/(optional more folders)
folder.
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('ping') //Command name
.setDescription('Replies with Pong!'), //Command description
testOnly: true, // If true, slash command will be added only to the test guild.
requiredPermissions: ['ADMINISTRATOR'], // Array of permissions that allow you to run the command.
async execute({ interaction, guild, member, user, channel, client } ) {
await interaction.reply('Pong!');
},
};
Note: This command template using SlashCommandBuilder
from @discordjs/builders
and you can use all functions from this builder. For example: subcommands, options etc.
When you added a new command to the bot or changed existing command properties, you must register it.
node deploy-commands.js
On top of your command add this line:
const language = require('../src/language');
Next if you want to get translation use:
language(guild, "TRANSLATE_NAME");
If you are creating embed, recommended is to use:
language.getEmbed(guild, "EMBED_NAME", "TRANSLATE_NAME");
- Open lang.json file.
- In
translations
object add new element:
"translations": {
"TRANSLATE_NAME": {
"english": "Translate name",
"polish": "Nazwa tłumaczenia",
[...]
},
[...]
}
- If you want to add translation for embed:
"translations": {
"EMBED_NAME": {
"TRANSLATE_NAME": {
"english": "Translate name",
"polish": "Nazwa tłumaczenia",
[...]
},
[...]
},
[...]
}
- Open
lang.json
file. - In
languages
object add new element:
"languages": [
"english",
"polish",
"your_language"
],
- Open
/commands/setup.js
file. - Add new choice to
language
subcommand:
.addSubcommand(subcommand =>
subcommand
.setName('language')
.setDescription('Choose language for bot')
.addStringOption(option => option.setName('language')
.setDescription('language that bot will use')
.addChoice('english', 'english')
.addChoice('polski', 'polish')
.addChoice('Language name displayed to user', 'your_language')
[...]
.setRequired(true))),
- Now deploy commands.
{
"DEFAULT_LANGUAGE": "english" // Defalut bot language.
}
// Required imports.
const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); // Provide intents for your bot.
commandHandler(client, Collection, {
commandsDir: path.join(__dirname, 'commands'), // Path to your commands folder.
eventsDir: path.join(__dirname, 'events') // Path to your events folder.
});
client.login(token);
Feel free to report bugs and contribute!