Gateway Events

General Structure

Events sent to and received from the gateway should always be of a common format. A field op specifies the opcode of the event, and an optional field d contains that event's data.

FieldTypeDescription
opStringThe opcode of the event. This is a unique identifier in SCREAMING_SNAKE_CASE.
d?ObjectA JSON-serialized object containing further information pertaining the event.

Here're a couple example payloads

/* A payload with no data */
{
  "op": "FOO"
}
/* A couple of payloads with data */
{
  "op": "FOO",
  "d": {
    "bar": "baz"
    }
}
{
  "op": "FOO",
  "d": [
    "bar",
    "baz"
    ]
}

Ping

The gateway expects to receive a ping every 45 seconds. A ping is a simple payload consisting of only an opcode. In response to a ping, the gateway will send back a pong.

FieldTypeDescription
opStringAlways "PING".

Example

{
  "op": "PING"
}

Pong

The response to a connected client's ping payload.

FieldTypeDescription
opStringAlways "PONG".

Example

{
  "op": "PONG"
}

Message Create

An event that is dispatched to all connected clients when a message is received. This event contains the message that triggered the event.

FieldTypeDescription
opStringAlways "MESSAGE_CREATE".
dMessageThe message object that triggered the event.

Example

{
  "op": "MESSAGE_CREATE",
  "d": {
    "author": "A certain woo",
    "content": "Woo!"
  }
}