Command methods

All commands are exported as objects which have properties to dictate how commands will work. Here is a complete list of all available methods:

Do not forget: onExecute or addSubCommand must be the last functions, so the command is properly registered.

Chat Input Command (Slash Command)

const { ChatInputCommand } = require('sl-commands')

new ChatInputCommand()
  /** The command name (required) */
  .setName('ping')
  /** The command description (required) */
  .setDescription('Shows my ping')
  /** If only bot developers will be able to use the command */
  .setDevsOnly(true)
  /** Whether the command will be only registered in test servers or not */
  .setTestOnly(true)
  /** There's a lot of types of options, this is one example of how to add one boolean option */
  .addBooleanOption(option =>
    option
      .setName('ephemeral')
      .setDescription('If the reply must be ephemeral')
      .setRequired(true)
  )
  /** The required server permissions for using the command */
  .setRequiredPermissions('Administrator')
  /** This will be executed whenever the command is used by someone */
  .onExecute(
    ({
      interaction, /** The slash command interaction */
      options, /** The options resolver for the command */
      handler, /** The SLHandler instance */
      channel, /** The channel where the command has been used */
      client, /** Your Discord Bot client */
      locale, /** The locale from the user who used the command */
      member, /** The member who used the command (might be undefined if used in a DM Channel) */
      guild, /** The guild where the command has been used (might be undefined if used in a DM Channel) */
      user, /** The user who used the command */
    }) => {
      interaction.reply(`Pong! ${user}`)
    }
  )

Message Context Menu (Right-click messages)

const { SLMessageCommand } = require('sl-commands')

new SLMessageCommand()
  /** The command name (required) */
  .setName('Content')
  /** If only bot developers will be able to use the command */
  .setDevsOnly(true)
  /** Whether the command will be only registered in test servers or not */
  .setTestOnly(true)
  /** The required server permissions for using the command */
  .setRequiredPermissions('ManageMessages', 'ViewChannel')
  /** This will be executed whenever the command is used by someone */
  .onExecute(
    ({
      interaction, /** The context menu interaction */
      target, /** The message which was selected by the user */
      handler, /** The SLHandler instance */
      channel, /** The channel where the command has been used */
      client, /** Your Discord Bot client */
      locale, /** The locale from the user who used the command */
      member, /** The member who used the command (might be undefined if used in a DM Channel) */
      guild, /** The guild where the command has been used (might be undefined if used in a DM Channel) */
      user, /** The user who used the command */
    }) => {
      interaction.reply(target.content)
    }
  )

User Context Menu (Right-click users)

const { SLUserCommand } = require('sl-commands')

new SLUserCommand()
  /** The command name (required) */
  .setName('Username')
  /** If only bot developers will be able to use the command */
  .setDevsOnly(true)
  /** Whether the command will be only registered in test servers or not */
  .setTestOnly(true)
  /** The required server permissions for using the command */
  .setRequiredPermissions('ManageNicknames')
  /** This will be executed whenever the command is used by someone */
  .onExecute(
    ({
      interaction /** The context menu interaction */,
      target /** The member who was selected by the user */,
      handler /** The SLHandler instance */,
      client /** Your Discord Bot client */,
      locale /** The locale from the user who used the command */,
      member /** The member who used the command (might be undefined if used in a DM Channel) */,
      guild /** The guild where the command has been used (might be undefined if used in a DM Channel) */,
      user /** The user who used the command */,
    }) => {
      interaction.reply(target.user.username)
    }
  )

Last updated