Skip to content
Classhttpv0.10.2

SlashHandler

Base class for a chat-input (slash) command handler on the HTTP transport.

Pass the route from the generated registry as the generic, then read this.options for a single command or this.match for several. Command authoring stays plain discord.js, seedcord codegen reads its toJSON() to type these options.

abstract class SlashHandler<
    Route extends keyof SlashRegistry
> extends InteractionHandler<APIChatInputApplicationCommandInteraction>

Member visibility

Filter class members by access level.

api

Typed Discord REST API (@discordjs/core/http-only) over core.rest, one instance per core. The interaction callbacks on api.interactions bypass the reply surface. The no-raw-interaction-acks rule flags them in handler classes.

protected api: API

Inherited from:RepliableHandler

dispatch

The bag for this dispatch. Each interaction gets its own. Every handler for one event shares a single bag.

protected readonly dispatch: DispatchContext

Inherited from:BaseHandler

event

protected readonly event: Event

Inherited from:BaseHandler

options

The typed options for this command's route. Only the getters for kinds this command declares appear. Each getter's name argument is restricted to that command's options of its kind.

  • A required option drops the null.

  • Choices narrow to their literal union.

  • A channel option declared with addChannelTypes narrows to those types.

Rich kinds resolve from the interaction's resolved data.

protected options: SlashOptions<Route>

sender

The reply surface for this interaction. Pass the handler to reply from outside its class.

readonly sender: TSender

Inherited from:RepliableHandler

delete()

Delete the initial reply or deferred placeholder. Pass a target to delete a message a prior send returned.

protected async delete(target?: TMessage): Promise<void>

Inherited from:RepliableHandler

execute()

Holds the main logic of your handler. The dispatcher calls it after the handler's gates pass, so a gate that refuses stops execute() from running.

abstract execute(): Promise<void>

Inherited from:BaseHandler

match()

Run the arm for whichever command fired. Use this only when the handler is registered for several routes.

Provide one arm per registered route, keyed by its route string, and each arm receives that route's own narrowed options. The arms must cover every route in the generic, a missing route or an unknown key is a compile error.

protected async match<Ret>(
    arms: SlashMatchArms<Route, Ret>
): Promise<Ret>
Parameter: arms

One handler per registered route, keyed by route string.