Skip to content

ComponentHandler

ComponentHandler is used to handle interactions from message components like buttons and select menus, based on a custom ID prefix.

new ComponentHandler(
prefix: string,
componentType: CType,
handler?: (interaction: MessageComponentInteractionObj<Context, CType>) => Promise<any> | any
)
  • prefix: string — The unique prefix of the custom_id to match this handler.
  • componentType: CType — The type of component (e.g., ComponentType.Button, ComponentType.StringSelect).
  • handler? — An optional initial handler function.

The type of component this handler is registered for.

The type identifier for this handler.

The custom ID prefix this handler listens for.

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

Sets the function to handle the component interaction.

execute(interaction: MessageComponentInteractionObj<Context, CType>): Promise<void>
Section titled “execute(interaction: MessageComponentInteractionObj<Context, CType>): Promise<void>”

Executes the registered handler.

Checks if a given customId matches this handler’s prefix.