Skip to content
V2 has arrived! A lot has changed, so treat this as a fresh start.

SlashCommandHandler

SlashCommandHandler is used to define and manage Discord slash commands. It extends @discordjs/builders’s SlashCommandBuilder.

new SlashCommandHandler();
addAutocompleteHandler(handler: (interaction: AutocompleteInteraction<Context>) => Promise<any> | any): this
Section titled “addAutocompleteHandler(handler: (interaction: AutocompleteInteraction<Context>) => Promise<any> | any): this”

Sets the function that will handle autocomplete interactions for this command.

Adds additional guild IDs to the existing set.

addHandler(handler: (interaction: ChatInputCommandInteraction<Context>) => Promise<any> | any): this
Section titled “addHandler(handler: (interaction: ChatInputCommandInteraction<Context>) => Promise<any> | any): this”

Sets the function that will handle the slash command interaction.

execute(interaction: ChatInputCommandInteraction<Context>): Promise<void>
Section titled “execute(interaction: ChatInputCommandInteraction<Context>): Promise<void>”

Executes the registered command handler.

executeAutocomplete(interaction: AutocompleteInteraction<Context>): Promise<void>
Section titled “executeAutocomplete(interaction: AutocompleteInteraction<Context>): Promise<void>”

Executes the registered autocomplete handler.

A set of guild IDs where this command is registered. If empty, the command is treated as a global command.

The type identifier for this handler.

Returns whether the command is restricted to specific guilds.

removeGuildIds(...guildIds: string[]): this
Section titled “removeGuildIds(...guildIds: string[]): this”

Removes specific guild IDs from the set.

Clears existing guild IDs and sets the provided ones.

The following methods from SlashCommandBuilder are overridden to return the SlashCommandHandler instance, allowing for fluent chaining:

  • addBooleanOption
  • addChannelOption
  • addIntegerOption
  • addMentionableOption
  • addNumberOption
  • addRoleOption
  • addStringOption
  • addSubcommand
  • addSubcommandGroup
  • addUserOption
  • addAttachmentOption