Pincer Core Module¶
Dispatching¶
GatewayDispatch¶
- class GatewayDispatch¶
Bases:
object
Represents a websocket message.
- seq¶
The sequence number of a message, which can be used for resuming sessions and heartbeats.
- Type
Optional[
int
]
Gateway¶
Dispatcher¶
- asyncclose
- asyncrestart
- defstart_loop
- 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.
- :param seq Optional[
- 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
- 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
socket (
WebSocketClientProtocol
) – The socket to send the heartbeat to.payload (
GatewayDispatch
) – The received hello message from the Discord gateway.
- Raises
HeartbeatError – No
heartbeat_interval
is present.
Http¶
HTTPClient¶
- class HTTPClient¶
Bases:
object
Interacts with Discord API through HTTP protocol
- await delete(route, headers=None)¶
This function is a coroutine.
Sends a delete request to a Discord REST endpoint.
- 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
- 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
- Returns
JSON response from the discord API.
- Return type
Optional[Dict]