Skip to content

Gateway

Internal API

These classes are for internal use only.

Users should interact with Client and other public API classes instead.


GatewayClient

Initialize this websocket.

Parameters:

  • gateway_url (str) –

    gateway URL provided by GET /gateway/bot endpoint

  • shard_id (int) –

    assigned shard ID

  • total_shards (int) –

    total shard count provided by GET /gateway/bot endpoint

  • logger (LoggerLike) –

    logger instance for logging events

logger = logger instance-attribute

shard_id = shard_id instance-attribute

total_shards = total_shards instance-attribute

ws = None instance-attribute

seq = None instance-attribute

session_id = None instance-attribute

allow_resume = False instance-attribute

heartbeat_task = None instance-attribute

heartbeat_interval = None instance-attribute

event_queue = asyncio.Queue() instance-attribute

base_url = gateway_url instance-attribute

url_params = '?v=10&encoding=json' instance-attribute

connect_ws async

Connect to Discord's Gateway (websocket).

start async

Starts the websocket and handles reconnections.

send async

Send data through the websocket.

receive async

Receive data through the websocket.

heartbeat async

Heartbeat task to keep connection alive.

identify async

Send an IDENTIFY payload to handshake for bot.

resume async

Send a RESUME payload to resume a connection.

_listen async

Listen for events and queue them to be picked up by Client.

close_ws async

Close the websocket connection if one is still open.


HelloEvent dataclass

Bases: Event, DataModel

Heartbeat interval event.

heartbeat_interval: int instance-attribute

Heartbeat interval in milliseconds.

name: str instance-attribute

Dispatch name of event.

raw: dict instance-attribute

Event's raw JSON payload. NOT A DATACLASS.

to_dict

Recursively turns the dataclass into a dictionary and drops empty fields.

Returns:

  • dict

    serialized dataclasss