the gateway is discord's real-time communication system. it's a websocket connection used for receiving events, maintaining presence, and handling voice updates.
connect to:
wss://gateway.discord.gg/?v=10&encoding=json
v=10specifies api version 10encoding=jsontells the gateway you want json-formatted messages
- connect to the gateway url
- receive the
op 10hello event - start sending heartbeats at the interval provided in hello
- send an
identifypayload with your auth token - receive
dispatchevents (READY,MESSAGE_CREATE, etc.)
websocket messages follow this format:
{
"op": 0,
"d": {},
"s": 42,
"t": "EVENT_NAME"
}where:
op(int): opcode that defines the message typed(object): event data payloads(int|null): sequence number for resuming sessionst(string|null): event name for dispatch events
| opcode | name | direction | description |
|---|---|---|---|
| 0 | dispatch | server → client | event notification (message created, etc.) |
| 1 | heartbeat | client → server | ping to keep connection alive |
| 2 | identify | client → server | authentication with token |
| 7 | reconnect | server → client | server asks you to reconnect |
| 9 | invalid session | server → client | session invalidated, need to re-identify |
| 10 | hello | server → client | sent immediately on connecting |
| 11 | heartbeat ack | server → client | confirms your heartbeat was received |
- rest api endpoints
- auth and token handling
- ratelimit guidelines
- voice connections
this documentation is released under the mit license.