Command Modules

Commands

You can create commands in reciple by creating a module that extends the built-in command modules:

The given module classes are mixin of BaseModule and Command Classes (which extends BaseCommand, which is the base class for all reciple modules.

Structure

  • data — A property that contains the command data. The command data is the definition of the command, such as the command name, description, options, etc.
  • execute — An async method that is called when the command is executed. The first parameter of the method is the command execute data.

When using a command builder, it is necessary to use the toJSON method to get the actual command data.

Slash Command

For better compatibility, import SlashCommandBuilder from reciple if you’re using a slash command builder.

import { SlashCommandBuilder, SlashCommandModule } from 'reciple';
import { InteractionContextType } from 'discord.js';

class ExampleCommand extends SlashCommandModule {
  data = new SlashCommandBuilder()
    .setName('example')
    .setDescription('An example command')
    .setContext(InteractionContextType.Guild)
    .toJSON();

  async execute({ interaction }) {
    await interaction.reply('Hello world!');
  }
}

export default new ExampleCommand();
Hello world!

Context Menu Command

For better compatibility, import ContextMenuCommandBuilder from reciple if you’re using a context menu command builder.

import { ContextMenuCommandBuilder, ContextMenuCommandModule } from 'reciple';
import { ApplicationCommandType } from 'discord.js';

class ExampleCommand extends ContextMenuCommandModule {
  data = new ContextMenuCommandBuilder()
    .setName('example')
    .setType(ApplicationCommandType.Message)
    .setDescription('An example command')
    .toJSON();

  async execute({ interaction }) {
    await interaction.reply('Hello world!');
  }
}

export default new ExampleCommand();
Hello world!

Message Command

Message command or prefix commands are commands that are executed when a message starts with a certain prefix. This is the ancient way of creating commands in discord.

import { MessageCommandBuilder, MessageCommandModule } from 'reciple';

class ExampleCommand extends MessageCommandModule {
  data = new MessageCommandBuilder()
    .setName('example')
    .setDescription('An example command')
    .toJSON();

  async execute({ message }) {
    await message.reply('Hello world!');
  }
}

export default new ExampleCommand();
!example !example Hello world!