Skip to content
Interfacegatewayv0.11.0

EventGateContext

The context that a gate gets on an event. It extends GuildPermissionsContext with the event payload and the djs objects derived from it. Names is the event(s) the gate supports, inferred from the ctx annotation, so a gate that reads one event's payload is rejected on a handler for a different event. The default supports every event.

interface EventGateContext<
    Names extends ValidNonInteractionKeys = ValidNonInteractionKeys
> extends GuildPermissionsContext
import { Events } from 'discord.js';

// gate keyed to one event, so payload is typed to that event's args tuple
const OnMessage = defineGate('msg', (ctx: EventGateContext<Events.MessageCreate>) => {
    void ctx.payload; // [Message]
});

appGuildPermissions

The bot's base permission set from the transport's cache. It's 0n in a guild the bot isn't in. It's null when the guild is cached but the bot's member isn't.

readonly appGuildPermissions: bigint | null

Inherited from:GuildPermissionsContext

core

The running framework, with the gateway's bot and bus.

readonly core: Core

dispatch

The bag for this dispatch, the same instance the handler and its middleware hold. Every middleware runs before the first gate. A gate can therefore read what a middleware wrote.

readonly dispatch: DispatchContext

Inherited from:GateContextBase

eventName

The event being handled.

readonly eventName: Names

guild

The guild derived from the payload, or null.

readonly guild: Guild | null

guildLocale

The guild's preferred language, or null outside a guild.

readonly guildLocale: Locale | null

Inherited from:DispatchOrigin

kind

The literal 'event', narrow on it before reading payload.

readonly kind: 'event'

member

The acting member derived from the payload, or null.

readonly member: GuildMember | null

memberGuildPermissions

The member's base permission set, roles only, matching djs GuildMember.permissions. Null when the member is unavailable.

readonly memberGuildPermissions: bigint | null

Inherited from:GuildPermissionsContext

memberPermissions

The member's permission bits, or null outside a guild. On an interaction these are the channel-scoped permissions the payload contains, and on a gateway event they're the member's guild-level ones.

readonly memberPermissions: bigint | null

Inherited from:GateContextBase

memberRoleIds

The member's role ids without the everyone role, the shape a raw interaction payload contains. Empty outside a guild, or when the event doesn't carry the member's roles.

readonly memberRoleIds: readonly string[]

Inherited from:GateContextBase

payload

The event's arguments, typed to that event's args tuple.

readonly payload: ClientEvents[Names]

user

The acting user derived from the payload, or null when the event doesn't have one.

readonly user: User | null

userId

The id of the user who triggered it, or null on an event without a user.

readonly userId: string | null

Inherited from:DispatchOrigin

userLocale

The language that the user picked in Discord, or null on a gateway event because a discord.js User doesn't have one.

readonly userLocale: Locale | null

Inherited from:DispatchOrigin