Skip to content

Gateway

Internal API

These classes are for internal use only.

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


gateway

logger = logging.getLogger('scurrypy.gateway') module-attribute

MIN_BACKOFF = 5 module-attribute

GatewayMetrics dataclass

heartbeat_rrt: float instance-attribute

GatewayClient

shard_id: int = 0 instance-attribute

total_shards: int = 0 instance-attribute

seq: int | None = None instance-attribute

session_id: str | None = None instance-attribute

allow_resume: bool = False instance-attribute

reconnect_immediately: bool = False instance-attribute

backoff: int = MIN_BACKOFF instance-attribute

metrics: GatewayMetrics = GatewayMetrics(0.0, 0.0) instance-attribute

heartbeat_task: asyncio.Task[None] | None = None instance-attribute

heartbeat_interval: int = 0 instance-attribute

event_queue: asyncio.Queue[tuple[str, JSON]] = asyncio.Queue() instance-attribute

base_url = 'wss://gateway.discord.gg' instance-attribute

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

ws: websockets.ClientConnection property

wait_reconnect async

Sleep for exponentially increasing time between reconnects.

start async

Start this websocket's connection.

Parameters:

  • token (str) –

    the bot's token

  • intents (int) –

    the bot's intents

  • shard_id (int) –

    shard ID to start

  • total_shards (int) –

    total number of shards to start

connect_ws async

Connect to Discord's Gateway (websocket).

send async

Send data through the websocket.

Parameters:

  • data (dict) –

    data to send

receive async

Receive data through the websocket.

Returns:

  • dict –

    websocket data

heartbeat async

Heartbeat task to keep connection alive.

identify async

Send an IDENTIFY payload to handshake for bot.

Parameters:

  • token (str) –

    the bot's token

  • intents (int) –

    the bot's intents

Raises:

  • ConnectionError –

    invalid intents

resume async

Send a RESUME payload to resume a connection.

Parameters:

  • token (str) –

    the bot's token

close_ws async

Close the websocket connection if one is still open and cancels heartbeat.