Gateway Opcodes
Every Gateway message is a JSON object with op, d, s, t. The opcode (op) defines the message role. Directions:
- C→S — client sends to server
- S→C — server sends to client
- C↔S — used both ways
| Code | Name | Direction | Description |
|---|---|---|---|
| 0 | DISPATCH | S→C | Server-to-client event. t holds the event type, d the payload. |
| 1 | HEARTBEAT | C↔S | Heartbeat. Client sends with the last s on the interval from HELLO. Server may also send one; reply immediately. |
| 2 | IDENTIFY | C→S | Starts a new session. Sent after HELLO. |
| 3 | PRESENCE_UPDATE | C→S | Update client status and activities. |
| 4 | VOICE_STATE_UPDATE | C→S | Join/leave a voice channel, mute, deafen. |
| 6 | RESUME | C→S | Resume an interrupted session with the last s. |
| 7 | RECONNECT | S→C | Server asks the client to reconnect and resume. |
| 8 | REQUEST_GUILD_MEMBERS | C→S | Request guild member list (for large guilds). |
| 9 | INVALID_SESSION | S→C | Session is invalid. d: true means resume is possible; false means re-identify. |
| 10 | HELLO | S→C | First message after connect. d.heartbeat_interval is the ms between heartbeats. |
| 11 | HEARTBEAT_ACK | S→C | Heartbeat acknowledgement. If missing, reconnect. |
| 12 | GATEWAY_ERROR | S→C | Gateway-level error with details in d. |
What’s next
Section titled “What’s next”- Connection lifecycle — how HELLO → IDENTIFY → READY form a working session
- Close codes — how to interpret a WebSocket close code
- Events — full list of dispatch events