discord-interactions

Gateway

class interactions.api.gateway.Heartbeat(ws: Any, interval: int)

A class representing a consistent heartbeat connection with the gateway.

Variables
  • ws (interactions.api.gateway.WebSocket) – The WebSocket class to infer on.

  • interval (typing.Union[int, float]) – The heartbeat interval determined by the gateway.

  • event (threading.Event) – The multi-threading event.

run() None

Starts the heartbeat connection.

stop() None

Stops the heartbeat connection.

class interactions.api.gateway.WebSocket(intents: interactions.api.models.intents.Intents, session_id: Optional[int] = None, sequence: Optional[int] = None)

A class representing a websocket connection with the gateway.

Variables
  • intents (interactions.api.models.intents.Intents) – An instance of interactions.api.models.Intents.

  • loop (asyncio.AbstractEventLoop) – The coroutine event loop established on.

  • req (interactions.api.http.Request) – An instance of interactions.api.http.Request.

  • dispatch (interactions.api.dispatch.Listener) – An instance of interactions.api.dispatch.Listener.

  • session (typing.Any) – The current client session.

  • session_id (int) – The current ID of the gateway session.

  • sequence (int) – The current sequence of the gateway connection.

  • keep_alive (interactions.api.gateway.Heartbeat) – An instance of interactions.api.gateway.Heartbeat.

  • closed (bool) – The current connection state.

  • http (interactions.api.http.HTTPClient) – The internal HTTP client used to connect to the gateway.

  • options (dict) – The websocket connection options.

async recv() Optional[Any]

Receives packets sent from the gateway.

async connect(token: str) None

Establishes a connection to the gateway.

Parameters

token (str) – The token to use for identifying.

Returns

None

handle(event: str, data: dict) None

Handles the dispatched event data from a gateway event.

Parameters
  • event (str) – The name of the event.

  • data (dict) – The data of the event.

Returns

None

contextualize(data: dict) object

Takes raw data given back from the gateway and gives “context” based off of what it is.

Parameters

data (dict) – The data from the gateway.

Returns

The context object.

async identify() None

Sends an IDENTIFY packet to the gateway.

async resume() None

Sends a RESUME packet to the gateway.

async heartbeat() None

Sends a HEARTBEAT packet to the gateway.