Skip to main content

๐Ÿ’ป Commands

Hey there ๐Ÿ‘‹! This guide is here to give you a fast understanding of how nyx's command system works, so you can use it right away. For in-depth details, see the respective guides of each command related object.

๐Ÿ“š Descriptionโ€‹

The command system in nyx is made up of several objects that work together to receive commands from users and routing said execution to the correspondent command object, all coordinated by a CommandManager.

Specifically, the command related objects are:

As well as the actual commands:

๐Ÿ”ข Slash command execution sequenceโ€‹

tip
  • A dashed step means it's executed asynchronously, so the next one is inmediately executed.
  • You can hover over steps with (?) to see extra details.

๐Ÿ“š Creating a commandโ€‹

The overall process of creating a command is to instantiate and register it to a CommandManager.

If the bot has started, it will immediately be deployed to Discord, and its ApplicationCommand mapping will be available on the CommandDeployer. If the bot hasn't started, it will be queued to be deployed once it starts if deployCommands is true.

Aditionally, commands don't depend on a specific bot, and you can reuse the same instance for many.

warning

By default, commands are registered using ApplicationCommandManager#set(). This means that commands deployed to Discord that are no longer registered will be deleted from there.

tip

Make sure to register all your commands before starting the bot to minimize the amount of API calls, since registering them after the bot has started will cause another API call.

โœจ Quick examplesโ€‹

  1. Extend AbstractStandaloneCommand, implementing execute() and createData().
  2. Register it to a bot's CommandManager.
class PingCommand extends AbstractStandaloneCommand {
protected createData() {
return new SlashCommandBuilder()
.setName('ping')
.setDescription('Pong!');
}

public async execute(interaction: ChatInputCommandInteraction) {
await interaction.reply('Pong!');
}
}

const command = new PingCommand();
await bot.getCommandManager().addCommands(command);

๐Ÿ”œ Next...โ€‹

Check the documentation of each command type:

Or check what you can do with commands: