Skip to content
Classgatewayv0.7.5

InteractionMiddleware

Base class for interaction middleware.

Middleware runs after the dispatcher builds the handler and before the gates, over the handler's own reply surface. Name the kinds in the generic and list the same ones in { kinds }. Several kinds give this.event a union. The discord.js guards narrow it. A catchall reads every repliable kind.

abstract class InteractionMiddleware<
    Kind extends MiddlewareKind = MiddlewareKind
> extends RepliableHandler<InteractionOf<Kind>>

Member visibility

Filter class members by access level.

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

sender

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

readonly sender: TSender

Inherited from:RepliableHandler

after()

Runs once the handler settles, newest middleware first. A refusal or a throw still reaches it, since seedcord calls it on every middleware whose execute() started. Implement it to release something this middleware took in execute(), such as a lock or an open span. A throw in here is logged and goes no further.

public async after?(result: DispatchResult): Promise<void>
Parameter: result

How the dispatch ended. Either failure state carries the thrown value on caught.

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