Class Gateway

The gateway manager. Manages shards, handles incoming payloads, and sends commands to the Discord gateway.

All events are emitted with their entire payload; Discord API Reference. Dispatched events are emitted under the * event prior to being passed through the cache event handler. After being handled by the cache manager, they are emitted again under their individual event name (example: GUILD_CREATE).

Hierarchy

Constructors

  • Create a gateway manager.

    Parameters

    • token: string

      The bot's token.

    • rest: Rest

      The rest manager to use for fetching gateway endpoints.

    • cache: false | Cache

      The cache to update from incoming events. If false is specified, gateway events will not be passed to a cache event handler.

    • options: GatewayOptions = {}
    • logCallback: LogCallback = ...

      A callback to be used for logging events internally in the gateway manager.

    • Optional logThisArg: any

      A value to use as this in the logCallback.

    Returns Gateway

Properties

managingShards: null | {
    offset: number;
    shards: number;
    totalBotShards: number;
} = null

The shard counts the manager is controlling.

options: Required<GatewayOptions> & {
    intents: number;
}

Options for the gateway manager. Note that any options not specified are set to a default value.x

shards: ExtendedMap<number, GatewayShard> = ...

Gateway shards. Modifying this map externally may result in unexpected behavior.

system: "Gateway" = ...

The system string used for logging.

user: null | APIUser = null

The latest self user received from the gateway.

Accessors

  • get averageHeartbeatPing(): number
  • The average heartbeat ping in milliseconds across all shards.

    Returns number

Methods

  • Connect to the gateway.

    Parameters

    • Optional gatewayBot: APIGatewayBotInfo

      A pre-fetched GET /gateway/bot. Not required, as this method will fetch it if not specified.

    Returns Promise<[number, number]>

    The results from shard spawns; [success, failed].

  • Get the average ping across all shards.

    Returns Promise<number>

  • Get members from a guild.

    See

    Discord API Reference

    Parameters

    • guildId: string

      The ID of the guild to get members from.

    • options: Partial<Omit<GatewayRequestGuildMembersDataWithQuery, "guild_id" | "presences">> & {
          user_ids?: string | string[];
      } = {}

      Guild member request options. By default, all members in the guild will be fetched.

    Returns Promise<{
        members: ExtendedMap<string, APIGuildMember>;
        notFound?: string[];
        presences?: ExtendedMap<string, GatewayPresenceUpdate>;
    }>

    Received members, presences, and missing members.

  • Get a guild's shard.

    See

    [Discord API Reference]

    Type Parameters

    • T extends boolean

    Parameters

    • guildId: string

      The guild's ID.

    • Optional ensure: T

      If true, an error is thrown if a GatewayShard is not found.

    Returns T extends true
        ? GatewayShard
        : number | GatewayShard

    The guild's shard, or a shard ID if the shard is not in this manager.

  • Update the bot's presence.

    Parameters

    • presence: GatewayPresenceUpdateData | GatewayPresenceUpdateData

      Presence data.

    • shard: number | number[] | "all" = ...

      A shard or shards to set the presence on. A number will set the presence on a single shard with a matching ID, a number array will set the presence on all shards matching am ID in the array, and all will set the presence on all shards.

    Returns Promise<void>

  • Update the bot's voice state.

    See

    Discord API Reference

    Parameters

    • guildId: string

      The guild to set the voice state in.

    • channelId: null | string

      The channel to join. nulldisconnects the bot.

    • mute: boolean = false

      If the bot should self mute.

    • deafen: boolean = false

      If the bot should self deafen.

    Returns Promise<void>

Generated using TypeDoc