Pincer Core Module

Dispatching

GatewayDispatch

class GatewayDispatch

Bases: object

Represents a websocket message.

op

The discord opcode which represents what the message means.

Type

int

data

The event data that has been sent/received.

Type

Optional[Union[int, Dict[str, Any]]]

seq

The sequence number of a message, which can be used for resuming sessions and heartbeats.

Type

Optional[int]

event_name

The event name for the payload.

Type

Optional[str]

classmethod from_string(payload)

Parses a given payload from a string format and returns a GatewayDispatch.

Parameters

payload (str) – The payload to parse.

Returns

The new class.

Return type

GatewayDispatch

Gateway

Dispatcher

Attributes
Methods
class Dispatcher

Bases: object

The Dispatcher handles all interactions with discord websocket API. This also contains the main event loop, and handles the heartbeat.

Running the dispatcher will create a connection with the Discord WebSocket API on behalf of the provided token.

This token must be a bot token. (Which can be found on https://discord.com/developers/applications/)

await close()

This function is a coroutine.

Stop the dispatcher from listening and responding to gateway events. This should let the client close on itself.

property intents

app.Intents

await restart(seq=None)

Restart the dispatcher.

:param seq Optional[int]: The sequence number of the last dispatched event.

If not provided, the dispatcher will restart with no base sequence.

start_loop(*, loop=None)

Instantiate the dispatcher, this will create a connection to the Discord websocket API on behalf of the client who’s token has been passed.

Parameters

loop (AbstractEventLoop) – The loop in which the Dispatcher will run. If no loop is provided it will get a new one.

Default: None

Heartbeat

Heartbeat

class Heartbeat

Bases: object

The heartbeat of the websocket connection.

This is what lets the server and client know that they are still both online and properly connected.

classmethod get()

Get the current heartbeat.

Returns

The current heartbeat of the client.

Default: 0 (client has not initialized the heartbeat yet.)

Return type

float

classmethod await handle_heartbeat(socket, _)

This function is a coroutine.

Handles a heartbeat, which means that it rests and then sends a new heartbeat.

Parameters
  • socket (WebSocketClientProtocol) – The socket to send the heartbeat to.

  • _ – Filling param for auto event handling.

classmethod await handle_hello(socket, payload)

This function is a coroutine.

Handshake between the discord API and the client. Retrieve the heartbeat for maintaining a connection.

Parameters
Raises

HeartbeatError – No heartbeat_interval is present.

classmethod update_sequence(seq)

Update the heartbeat sequence.

Parameters

seq (int) – The new heartbeat sequence to be updated with.

Http

HTTPClient

Attributes
Methods
class HTTPClient

Bases: object

Interacts with Discord API through HTTP protocol

url

f"https://discord.com/api/v{version}" “Base url for all HTTP requests”

Type

str

max_tts

Max amount of attempts after error code 5xx

Type

int

await close()

This function is a coroutine.

Closes the aiohttp session

await delete(route, headers=None)

This function is a coroutine.

Sends a delete request to a Discord REST endpoint.

Parameters
  • route (str) – The Discord REST endpoint to send a delete request to.

  • headers (Optional[Dict[str, Any]]) – The request headers.

    Default: None

Returns

The response from discord.

Return type

Optional[Dict]

await get(route)

This function is a coroutine.

Sends a get request to a Discord REST endpoint.

Parameters

route (str) – The Discord REST endpoint to send a get request to.

Returns

The response from discord.

Return type

Optional[Dict]

await head(route)

This function is a coroutine.

Sends a head request to a Discord REST endpoint.

Parameters

route (str) – The Discord REST endpoint to send a head request to.

Returns

The response from discord.

Return type

Optional[Dict]

await options(route)

This function is a coroutine.

Sends a options request to a Discord REST endpoint.

Parameters

route (str) – The Discord REST endpoint to send a options request to.

Returns

The response from discord.

Return type

Optional[Dict]

await patch(route, data=None, content_type='application/json', headers=None)

This function is a coroutine.

Sends a patch request to a Discord REST endpoint.

Parameters
  • route (str`) – The Discord REST endpoint to send a patch request to.

  • data (Dict) – The update data for the patch request.

  • content_type (str) – Body content type.

    Default: application/json

  • headers (Optional[Dict[str, Any]]) – The request headers.

Returns

JSON response from the discord API.

Return type

Optional[Dict]

await post(route, data=None, content_type='application/json', headers=None)

This function is a coroutine.

Sends a post request to a Discord REST endpoint

Parameters
  • route (str) – The Discord REST endpoint to send a patch request to.

  • data (Dict) – The update data for the patch request.

  • content_type (str) – Body content type.

    Default: application/json

  • headers (Optional[Dict[str, Any]]) – The request headers.

Returns

JSON response from the discord API.

Return type

Optional[Dict]

await put(route, data=None, content_type='application/json', headers=None)

This function is a coroutine.

Sends a put request to a Discord REST endpoint

Parameters
  • route (str) – The Discord REST endpoint to send a patch request to.

  • data (Dict) – The update data for the patch request.

  • content_type (str) – Body content type.

    Default: application/json

  • headers (Optional[Dict[str, Any]]) – The request headers.

Returns

JSON response from the discord API.

Return type

Optional[Dict]