> For the complete documentation index, see [llms.txt](https://docs.iynxdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.iynxdev.com/addon-api/getting-started/commands.md).

# 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.

```js
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);
    }
  }
};
```

2. Create a new command file inside your `/plugins/<plugin_name>/src/commands/` directory.
3. 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](https://discordjs.guide/slash-commands/parsing-options.html#parsing-options) object.
* **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](https://discordjs.guide/slash-commands/autocomplete.html#handling-multiple-autocomplete-options) for handling multiple options in a single command file.

***

## 3. Additional information

{% hint style="warning" %}
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.
{% endhint %}

```js
try {
  // Your code here
}
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 });
}
```

{% hint style="info" %}
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.
{% endhint %}
