For the complete documentation index, see llms.txt. This page is also available as Markdown.

Commands

This page explains how to create your own commands for your AthenaBot plugin.


1. Setting up the command file

  1. 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);
    }
  }
};
  1. Create a new command file inside your /plugins/<plugin_name>/src/commands/ directory.

  2. The name of the file must follow the format <command_name>.js.

Parameters

  • name: The name of the command.

  • contextMenu: Set to true for 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 null to 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 also provides custom embed builders for warnings, errors, and success messages. It is recommended to use these builders to maintain consistency across your plugin. See the internal API documentation for more details.

Last updated