Commands
This page explains how to create your own commands for your AthenaBot plugin.
1. Setting up the command file
Copy the command template.
const { SlashCommandBuilder, MessageFlags } = require('discord.js');
const command = require('../../../../main/discord/core/commands/command.js');
module.exports = class test extends command {
constructor(heart) {
const helloConfig = heart.core.discord.core.config.manager.get('hello').get();
super(heart, {
name: 'test',
data: new SlashCommandBuilder()
.setName('test')
.setDescription('Test command')
.addStringOption(option => option.setName('name').setDescription('Name').setAutocomplete(true).setRequired(true)),
contextMenu: false,
global: true,
category: 'general',
bypass: true,
permissionLevel: helloConfig.config.permissions.test_command,
});
}
async execute(interaction, langConfig) {
try {
const name = interaction.options.getString('name');
interaction.reply({ content: `Hello World, ${name}!`, flags: MessageFlags.Ephemeral });
}
catch (err) {
this.heart.core.console.log(this.heart.core.console.type.error, `An issue occurred while executing command ${this.getName()}`);
new this.heart.core.error.interface(this.heart, err);
interaction.reply({ embeds: [this.heart.core.util.discord.generateErrorEmbed(langConfig.lang.unexpected_command_error.replace(/%command%/g, `/${interaction.commandName}`))], flags: MessageFlags.Ephemeral });
}
}
async autocomplete(interaction) {
try {
await interaction.respond([{ name: 'Test', value: 'test' }]);
}
catch (err) {
this.heart.core.console.log(this.heart.core.console.type.error, `An issue occurred while executing autocomplete event ${this.getName()}`);
new this.heart.core.error.interface(this.heart, err);
}
}
};Create a new command file inside your
/plugins/<plugin_name>/src/commands/directory.The name of the file must follow the format
<command_name>.js.
Parameters
name: The name of the command.
data: A Discord slash command builder object.
contextMenu: Set to
truefor a context menu command; otherwise,false.global: Keep this as
true.category: Help category for the command. Keep this as
general.bypass: Must remain
true.permissionLevel: The required permission level to execute the command. Set to
nullto allow everyone to execute it.
2. Command response
There are two main interaction types you may need to handle in your command file:
Autocomplete interaction — only if you enabled an autocomplete parameter.
Default command interaction.
Command interaction
This is the standard interaction from discord.js. You can respond and handle the interaction however you like.
Autocomplete interaction
This is also the standard discord.js interaction. You can respond and handle it however you like.
If your command has multiple autocomplete parameters enabled, check out this guide for handling multiple options in a single command file.
3. Additional information
Athena provides a custom error logging system that is deeply integrated into the framework. Do not throw errors directly. Instead, catch them and handle them with Athena’s error interface.
Last updated