# EventGateContext

`interface` in `gateway` · v0.5.1

<https://docs.seedcord.org/packages/gateway/0.5.1/interfaces/event-gate-context>

The event arm. It extends [`GuildPermissionsContext`](/packages/core/0.7.0/interfaces/guild-permissions-context) 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.

```ts
interface EventGateContext<
    Names extends ValidNonInteractionKeys = ValidNonInteractionKeys
> extends GuildPermissionsContext
```

## Examples

```ts
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]
});
```

## Properties

### appGuildPermissions

```ts
readonly appGuildPermissions: bigint | null
```

The bot's base permission set from the transport's cache. Null when the cached member is unavailable.

### appPermissions

```ts
readonly appPermissions: bigint | null
```

The bot's permissions in the invoked channel, the wire `app_permissions` value. Null on gateway events.

### channelId

```ts
readonly channelId: string | null
```

The channel id, or null when the source carries none.

### core

```ts
readonly core: Core
```

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

### eventName

```ts
readonly eventName: Names
```

The event being handled.

### guild

```ts
readonly guild: Guild | null
```

The guild derived from the payload, or null.

### guildId

```ts
readonly guildId: string | null
```

The guild id, or null outside a guild.

### kind

```ts
readonly kind: 'event'
```

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

### member

```ts
readonly member: GuildMember | null
```

The acting member derived from the payload, or null.

### memberGuildPermissions

```ts
readonly memberGuildPermissions: bigint | null
```

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

### memberPermissions

```ts
readonly memberPermissions: bigint | null
```

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.

### memberRoleIds

```ts
readonly memberRoleIds: readonly string[]
```

The member's role ids without the everyone role, the shape a raw interaction payload contains. Empty outside a guild or when the source contains none.

### payload

```ts
readonly payload: ClientEvents[Names]
```

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

### routeId

```ts
readonly routeId: string | null
```

The dispatched handler as `kind:route` (`slash:daily`, `button:confirm`), or null off a route (a plain event handler, or a gate run outside a handler). `runHandlerGates` sets it from the handler's metadata. `Cooldown` uses it so its window is stable across restarts and isolates.

### user

```ts
readonly user: User | null
```

The acting user derived from the payload, or null when the event carries none.

### userId

```ts
readonly userId: string | null
```

The acting user's id, or null on an event that carries none.
