Skip to content
Classhttpv0.10.2

ModalHandler

Base class for a modal submit handler on the HTTP transport.

Register the customId definitions this handler decodes with @ModalRoute and list the same ones in the generic. Read the submitted inputs from this.fields. Reply through the handler members. showModal fails compilation on this kind, because Discord forbids opening a modal in response to a modal.

abstract class ModalHandler<
    Defs extends readonly AnyCustomId[]
> extends ComponentHandler<APIModalSubmitInteraction, Defs>

Member visibility

Filter class members by access level.

Defs

The customId definitions this handler decodes, e.g. [typeof ConfigId].

Defs extends readonly AnyCustomId[]

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

fields

The fields this modal submitted, read by custom id.

protected fields: ModalFields

params

The decoded params of the single route this handler is registered for.

Reading this decodes this.event.data.custom_id once (cached after the first read) and throws StaleCustomId or InvalidCustomId when the wire no longer matches the current shape, which the dispatcher boundary turns into a reply. On a handler registered for several routes this is never, so use match instead.

protected params: SingleParams<Defs>

Inherited from:ComponentHandler

sender

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

readonly sender: TSender

Inherited from:RepliableHandler

deferUpdate()

Acknowledge the submit without changing the source message. Throws when a command opened the modal.

protected override async deferUpdate(): Promise<void>

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 route the component was minted from. Use this only when the handler is registered for several routes. A single-route handler reads this.params directly. On a multi-route handler this.params is never, so match is the only way to read the decoded params.

Provide one arm per registered route, keyed by its prefix, and each arm receives that route's own decoded params. The arms cover every registered route prefix, checked at compile time, and a prefix unmatched at runtime throws CustomIdMatchArmMissing. Decoding runs before any arm, so a stale or corrupt wire throws before an arm body executes.

protected async match<Ret>(arms: MatchArms<Defs, Ret>): Promise<Ret>
Parameter: arms

One callback per registered route, keyed by prefix.

Inherited from:ComponentHandler

update()

Rewrite the message this modal was opened from. Throws when a command opened the modal.

protected override async update(
    response: ReplyResponse | string
): Promise<SentMessage>