Skip to content

ContextCommandHandler

ContextCommandHandler is used to define and manage Discord context menu commands (User or Message). It extends @discordjs/builders’s ContextMenuCommandBuilder.

new ContextCommandHandler(commandType: ContextCommandType)
  • commandType: ContextCommandType — Either ContextCommandType.User or ContextCommandType.Message.
commandType: ContextCommandType (readonly)
Section titled “commandType: ContextCommandType (readonly)”

The type of context command (User or Message).

A set of guild IDs where this command is registered. If empty, it’s a global command.

The type identifier for this handler.

Adds guild IDs to the existing set.

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

Sets the function to handle the context menu interaction.

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

Executes the registered handler.

Returns whether the command is restricted to specific guilds.

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

Removes specific guild IDs.

Clears and sets the guild IDs.