discord.payload module

class discord.payload.Payload(opcode, data, seq_number=None, event_name=None)[source]

Bases: object

A discord gateway payload as described here: https://discordapp.com/developers/docs/topics/gateway#payloads

Parameters:
DISPATCH = 0
HEARTBEAT = 1
IDENTIFY = 2
STATUS_UPDATE = 3
VOICE_UPDATE = 4
RESUME = 6
RECONNECT = 7
REQUEST_MEMB = 8
INVALID = 9
HELLO = 10
HEARTBEAT_ACK = 11
static from_packet(packet)[source]

Creates a Payload from the raw string received through the gateway websocket.

Parameters:packet – The json string receveid from the gateway.
Returns:A Payload.
to_packet()[source]

Encodes the payload in json in a format recognized by discord’s APIs.

Returns:A json string.
static Resume(token, session_id, last_seq)[source]

Creates a RESUME payload.

Parameters:
  • token – The bot token.
  • session_id – The id of the session that was opened with the gateway’s websocket.
  • last_seq – The last payload sequence number received before the connection was interrupted.
Returns:

A RESUME Payload.

static Identify(token, os, name)[source]

Creates an IDENTIFY payload.

Parameters:
  • token – The bot token.
  • os – The OS of the machine on which the bot runs.
  • name – The bot’s name.
Returns:

An IDENTIFY Payload.