SlashCommandHandler
SlashCommandHandler is used to define and manage Discord slash commands. It extends @discordjs/builders’s SlashCommandBuilder.
Constructor
Section titled “Constructor”new SlashCommandHandler();Public Properties
Section titled “Public Properties”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.
addGuildIds(...guildIds: string[]): this
Section titled “addGuildIds(...guildIds: string[]): this”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.
guildIds: Set<string> (readonly)
Section titled “guildIds: Set<string> (readonly)”A set of guild IDs where this command is registered. If empty, the command is treated as a global command.
handlerType: "slash" (readonly)
Section titled “handlerType: "slash" (readonly)”The type identifier for this handler.
isGuildCommand(): boolean
Section titled “isGuildCommand(): boolean”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.
setGuildIds(guildIds: string[]): this
Section titled “setGuildIds(guildIds: string[]): this”Clears existing guild IDs and sets the provided ones.
Public Methods
Section titled “Public Methods”Overridden SlashCommandBuilder Methods
Section titled “Overridden SlashCommandBuilder Methods”The following methods from SlashCommandBuilder are overridden to return the SlashCommandHandler instance, allowing for fluent chaining:
addBooleanOptionaddChannelOptionaddIntegerOptionaddMentionableOptionaddNumberOptionaddRoleOptionaddStringOptionaddSubcommandaddSubcommandGroupaddUserOptionaddAttachmentOption