EventMiddleware
Base class for Discord event middleware.
Middleware runs before event handlers and can stop the event by throwing a Silence. Unlike EventHandler, it
doesn't take a match because it runs the SAME for every event it is registered for. Specify a single event in the
generic and { events } to read this.event fully typed. If you span several events (or omit { events } for
a catchall), this.event narrows to never. Read this.route there, for work that doesn't depend on the
payload shape. Write one class per event for a middleware that needs each event's payload.
abstract class EventMiddleware<
EventName extends ValidNonInteractionKeys = ValidNonInteractionKeys
> extends BaseHandler<ClientEvents[EventName]>Member visibility
Filter class members by access level.
EventMiddleware(
event: ClientEvents[EventName],
core: Core,
dispatch: DispatchContext
)EventName
One or more ClientEvents keys. Defaults to every event (catchall).
EventName extends ValidNonInteractionKeys = ValidNonInteractionKeyscore
readonly core: TCoreInherited from:BaseHandler
dispatch
The bag for this dispatch. Each interaction gets its own. Every handler for one event shares a single bag.
protected readonly dispatch: DispatchContextInherited from:BaseHandler
protected readonly event: SingleEventPayload<EventName>logger
protected readonly logger: LoggerInherited from:BaseHandler
protected readonly route: EventNamepublic after?(result: EventDispatchResult): Promisable<void>resultoutcome reports the chain alone. handlers holds one entry per handler that
ran, empty exactly when the chain stopped the event.
// the base declares it. an implementation carries `override`.
override async after(result: EventDispatchResult) {
this.span.end();
}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
getEvent(): ValidEventInherited from:BaseHandler