Skip to content
Classgatewayv0.7.5

EventHandler

Base class for a Discord client event handler.

Pass the event name(s) as the generic, the same one(s) as @RegisterEvent. A single-event handler reads this.event (the payload tuple) directly. A handler registered for several events branches with this.match, keyed by event name, since the union of payload tuples is not directly readable.

abstract class EventHandler<
    Names extends ValidNonInteractionKeys
> extends BaseHandler<ClientEvents[Names]>

Member visibility

Filter class members by access level.

constructor

Constructs a new instance of the EventHandler class

EventHandler(
    event: ClientEvents[Names],
    core: Core,
    dispatch: DispatchContext,
    eventName?: Names
)

Showing members with Protected visibility and higher.

Names

One or more ClientEvents keys, e.g. Events.MessageCreate or Events.MessageCreate | Events.MessageUpdate.

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

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

getEvent()

getEvent(): ValidEvent

Inherited from:BaseHandler

match()

Run the arm for whichever event fired. Use this only when the handler is registered for several events. A single-event handler reads this.event directly. On a multi-event handler this.event is never, so match is the only way to read the payload.

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

protected async match<Ret>(
    arms: EventMatchArms<Names, Ret>
): Promise<Ret>
Parameter: arms

One handler per registered event, keyed by event name.