Skip to content

HandlerFunction

The HandlerFunction type represents the core logic for any interaction handler. It is the function that gets executed when a specific interaction matches a registered handler.

export type HandlerFunction<
Context extends BaseInteractionContext = BaseInteractionContext,
InteractionArg extends AnyInteraction<Context> = AnyInteraction<Context>,
> = (interaction: InteractionArg) => Promise<any> | any;

A HandlerFunction receives an interaction object (which includes the context) and can perform any logic required. It typically returns a promise, but can also be synchronous.

The InteractionArg will be one of the interaction classes (e.g., ChatInputCommandInteraction, ButtonInteraction, etc.) depending on what the handler is registered for.

All interaction arguments share a c (context) property which is the BaseInteractionContext.