Skip to content
Classgatewayv0.9.0

ModalHandler

Base class for a modal submit handler.

Register the customId definitions this handler decodes with @ModalRoute, list the same ones in the generic, then read this.params for a single route or this.match for several. 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[],
    Cache extends CacheType = "cached"
> extends ComponentHandler<ModalSubmitInteraction<Cache>, Defs>

Member visibility

Filter class members by access level.

Defs

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

Defs extends readonly AnyCustomId[]

Cache

The interaction cache state, 'cached' by default.

Cache extends CacheType = 'cached'

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: ModalSubmitFields<Cache>

params

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

Reading this decodes this.event.customId once and caches the result. On a handler registered for several routes this is never. Use match instead.

protected params: SingleParams<Defs>

Inherited from:ComponentHandler

Throws:

  • A StaleCustomId when the wire was encoded under an older shape. The controller boundary turns it into a reply.

  • An InvalidCustomId when the wire is corrupt. The controller boundary turns it into a reply.

route

The matched custom-ID prefix, such as approve, without encoded params.

protected readonly route: Defs[number]['prefix']

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(): Promisable<void>

Inherited from:BaseHandler

match()

Run the case for whichever route the component was minted from. Use this only when the handler is registered for several routes. On a single-route handler, read this.params directly. On a multi-route handler this.params is never, leaving match as the only way to read the decoded params.

Provide one case per registered route, keyed by its prefix, and each case receives that route's own decoded params. The compiler checks that the cases cover every registered route prefix. match decodes the wire before it runs a case.

protected async match<Ret, Cases>(
    cases: OnlyCases<Cases, MatchCases<Defs, Ret>>
): Promise<MatchResult<Ret, Cases>>
Parameter: cases

One callback per registered route, keyed by prefix.

Type parameter: Ret

The type that every case must return. Leave it out to get the union of what the cases return.

Throws:

A SeedcordTypeError with MatchCaseMissing when the wire's prefix doesn't have a case.

Throws:

A StaleCustomId when the wire was encoded under an older shape.

Throws:

An InvalidCustomId when the wire is corrupt.

Inherited from:ComponentHandler