Client commands
Clients send commands over the Gateway WebSocket as JSON, with an opcode in op and the data in d.
Command list
Заголовок раздела «Command list»| Opcode | Command | Result |
|---|---|---|
| 1 | Heartbeat | Opcode 11 Heartbeat ACK |
| 2 | Identify | Ready, opcode 7 from a draining node, a close frame, or no response while the Gateway keeps the Identify waiting |
| 3 | Presence Update | None |
| 4 | Voice State Update | Voice State Update and Voice Server Update |
| 6 | Resume | Replayed Dispatches and Resumed, Invalid Session, or a close frame |
| 8 | Request Guild Members | Guild Members Chunk |
| 13 | Voice Signal | Voice Signal for the target connection |
| 14 | Lazy Request | Guild Sync and member list and thread list updates |
| 15 | Request Guild Counts | Guild Counts Update |
| 16 | Request Channel Member Counts | Channel Member Counts Update |
| 28 | Request Forum Unreads | Forum Unreads |
Every command counts against the payload budgets.
Malformed commands
Заголовок раздела «Malformed commands»| Payload | Close code | Reason |
|---|---|---|
| A command other than Heartbeat, Identify and Resume before Identify or Resume | 4003 | Not authenticated |
| No Identify or Resume within one heartbeat interval of Hello | 4003 | Not authenticated |
| More than 64 commands between Identify and Ready, or between Resume and Resumed | 4008 | Rate limited |
| A frame that does not decode to an object | 4002 | Decode failed |
An object with no op | 4002 | Invalid payload |
| An unknown opcode, once the session is authenticated | 4001 | Unknown opcode |
A payload with op but no d, other than Identify and Resume | 4001 | Unknown opcode |
Identify or Resume with no d, or on a session that is already authenticated | 4005 | Already authenticated |
Request Guild Members, Lazy Request, Request Guild Counts and Request Channel Member Counts never close the connection when they have a d, and they skip input they cannot parse. Request Forum Unreads closes with 4001 when its d is not an object.
Heartbeat
Заголовок раздела «Heartbeat»Opcode 1 sends the last Dispatch sequence the client processed, or null before the first Dispatch. The connection closes with 4009 when the heartbeat timeout passes with no acknowledgement.
| Field | Type | Description |
|---|---|---|
| d | ?integer | The last Dispatch sequence the client processed |
{ "op": 1, "d": 42}Once authenticated, a d that is neither null nor an integer closes with 4007 and reason Invalid sequence.
Identify
Заголовок раздела «Identify»Opcode 2 authenticates and creates a new session.
| Field | Type | Description |
|---|---|---|
| token | string | The account or bot token, with no HTTP authentication prefix |
| properties | identify properties object | The software and capabilities of the connecting client |
| presence?1 | ?initial presence object | The presence to publish when the session starts |
| ignored_events?2 | ?array[string] | The Dispatch event names this session does not want (at most 256) |
| flags? | integer | A non-negative session flags bitfield (default 0) |
| initial_guild_id?3 | ?snowflake | The snowflake of one guild the session joins as active |
| shard?4 | ?array[integer] | The [shard_id, shard_count] pair |
1 Null and an omitted key both use the account’s saved status and custom status
2 An ignored Message Create still arrives for a direct, @here or @everyone mention, and a dropped event uses no sequence number
3 The session is active in that guild without a Lazy Request and gets no initial Guild Sync. An invalid value is ignored
4 shard_id is at least 0 and lower than shard_count, which is from 1 to 16,384
{ "op": 2, "d": { "token": "...", "properties": { "os": "Linux", "browser": "Squad Client", "device": "desktop" }, "presence": { "status": "online", "afk": false, "mobile": false }, "ignored_events": ["TYPING_START"], "flags": 2, "initial_guild_id": "1189375284394692608" }}Identify closes the connection on these faults.
| Fault | Close code | Reason |
|---|---|---|
A missing token or properties, or an invalid properties, ignored_events or flags | 4002 | Invalid identify payload |
A token that isn’t a string of 1 to 256 bytes with at least one visible character | 4004 | Invalid token |
Malformed shard | 4010 | Invalid shard |
A bot session with more than 2,500 guilds after the shard filter | 4011 | Sharding required |
| The backend rejects the token | 4004 | Invalid token |
| A non-bot account with 100 live sessions | 4008 | Too many sessions |
| The socket already has a session | 4005 | Already authenticated |
Session flags
Заголовок раздела «Session flags»| Value | Name | Description |
|---|---|---|
| 1 << 1 | DEBOUNCE_MESSAGE_REACTIONS | Merges runs of reactions into Message Reaction Add Many |
| 1 << 2 | CHANNEL_THREADS | The client can parse thread, forum and media channels |
| 1 << 3 | GUILD_VISITS | The session receives the guilds the account is visiting |
Undefined bits are ignored.
Identify properties object
Заголовок раздела «Identify properties object»Structure
Заголовок раздела «Structure»| Field | Type | Description |
|---|---|---|
| os | string | The operating system the client runs on |
| browser | string | The client library identifier |
| device | string | The device or application identifier |
| e2ee_capable?1 | boolean | Whether the client can take part in voice with encrypted call media |
| mobile?2 | boolean | Whether the session is mobile (default false) |
| latitude?3 | number or string | The client latitude, at most 32 characters as a string |
| longitude?3 | number or string | The client longitude, at most 32 characters as a string |
1 A session without it gets VOICE_E2EE_REQUIRED when it joins a voice channel with encrypted call media
2 Used only when presence is absent or null. Otherwise the initial presence object decides
3 Send both to order the Ready rtc_regions array by distance
Initial presence object
Заголовок раздела «Initial presence object»Structure
Заголовок раздела «Structure»| Field | Type | Description |
|---|---|---|
| status?1 | string | The initial status, one of online, idle, dnd, invisible or offline |
| afk? | boolean | Whether the session is away (default false) |
| mobile? | boolean | Whether the presence is mobile (default false) |
| custom_status?2 | ?custom status object | The custom status this session publishes |
1 Squad uses the account’s saved status when status is missing, empty or not one of these values, and when it is online but the saved status is something else
2 Used only when the account has no saved custom status, and stored as sent
A session whose status is offline or invisible shows as offline with no custom status to other users.
Custom status object
Заголовок раздела «Custom status object»Structure
Заголовок раздела «Structure»| Field | Type | Description |
|---|---|---|
| text? | ?string | The text of the custom status (1-128 characters) |
| expires_at?1 | ?ISO8601 timestamp | The time the custom status expires |
| emoji_id?2 | ?snowflake | The snowflake of the custom emoji |
| emoji_name?3 | ?string | The Unicode emoji (1-32 characters) |
1 Must be in the future
2 Must be an existing emoji. Squad drops the field when the account has no global expressions entitlement
3 A single Unicode emoji, which is ignored when emoji_id is sent
Presence Update events also include emoji_animated.
Opcode 6 restores a retained session. All fields are required, and a missing or mistyped field closes with 4002 and reason Invalid resume payload.
| Field | Type | Description |
|---|---|---|
| token | string | The token that owns the retained session |
| session_id | string | The session ID from Ready |
| seq | integer | The last Dispatch sequence the client processed |
Send Resume on a new socket. Squad replays every retained Dispatch above seq in order and then sends Resumed. If another socket still has the session, that socket gets opcode 7 and is closed.
| Condition | Result |
|---|---|
| Unknown or expired session | Opcode 9 with d: false |
seq below the replay floor | Opcode 9 with d: false |
| Token does not own the session | Close code 4004, reason Invalid token |
seq is negative, above the session sequence or below the acknowledged one | Close code 4007, reason Invalid sequence |
| The session can’t be restored right now | Close code 4000, reason Session unavailable |
| The socket already has a session | Close code 4005, reason Already authenticated |
Presence Update
Заголовок раздела «Presence Update»Opcode 3 replaces the current session presence. Updates over the Presence Update limit are dropped without a close.
| Field | Type | Description |
|---|---|---|
| status | string | The status to publish, one of online, idle, dnd, invisible or offline |
| afk? | boolean | Whether the session is away (default false) |
| mobile? | boolean | Whether the session is mobile (default false) |
| custom_status?1 | ?custom status object | The custom status that replaces the current one |
1 Omitting the key keeps the current custom status and null clears it. A rejected object, such as one from a limited account, leaves it unchanged
{ "op": 3, "d": { "status": "idle", "afk": true, "mobile": false, "custom_status": { "text": "away from keyboard" } }}A payload that is not an object, has no status, or has a non-empty string status outside the set closes with 4002 and reason Invalid presence payload. An empty string or a status that isn’t a string counts as online, and an offline status is stored as invisible.
Voice State Update
Заголовок раздела «Voice State Update»Opcode 4 joins, moves, updates or leaves the voice membership of the current session. Every field is optional. A d that is not an object closes with 4002 and reason Invalid voice payload, and other invalid updates are dropped.
| Field | Type | Description |
|---|---|---|
| guild_id? | ?snowflake | The guild with the voice channel, where null selects the direct message and group direct message call context |
| channel_id? | ?snowflake | The channel to join or move to, where null leaves the membership |
| connection_id?1 | ?string | The existing voice connection this update applies to |
| self_mute?2 | boolean | Whether the client has muted its microphone (default false) |
| self_deaf?2 | boolean | Whether the client has deafened its output (default false) |
| self_video?2 | boolean | Whether the client publishes camera video (default false) |
| self_stream?3 | boolean | Whether this connection advertises a screenshare track (default false) |
| is_mobile?2 | boolean | Whether this is a mobile voice client (default false) |
| viewer_stream_keys?4 | ?array[string] | The stream keys this connection watches, where an omitted key keeps the list and null clears it |
| latitude? | number or string | The client latitude, used to pick a voice region |
| longitude? | number or string | The client longitude, used to pick a voice region |
| p2p?5 | boolean | Whether the client agrees to peer-to-peer media for a new connection, or leaves the mesh on an existing one |
1 A channel_id with no connection_id opens a new connection and one with it updates or moves that connection. Leaving a guild with channel_id: null and no connection_id disconnects every connection the session has in that guild
2 Only true and the string "true" set the flag
3 Set like the other flags, and false is published when the member lacks STREAM in the channel. It sends no Voice Server Update
4 Each entry is the stream key of a live connection that matches this update’s scope, guild and channel. Squad drops an update with any other entry
5 Only the JSON Boolean true agrees. On an existing connection, false moves the whole channel or call to LiveKit, except in a guild voice channel with rtc_p2p set. A bot session never agrees
{ "op": 4, "d": { "guild_id": "1189375284394692608", "channel_id": "1189375284394692610", "self_mute": false, "self_deaf": false, "self_video": false, "self_stream": false }}guild_id: null with channel_id: null and a connection_id leaves that direct message or group direct message call connection. Without a connection_id it disconnects the session from every voice membership.
Joining or moving sends Voice Server Update to you and Voice State Update to every session that can see the channel. A refused join comes back as a Gateway Error with the refusal code.
Updates over the Voice State Update limit are queued, and a newer update for the same guild_id and connection_id replaces one that is still waiting.
Voice Signal
Заголовок раздела «Voice Signal»Opcode 13 sends one signalling message to another connection in a peer-to-peer voice channel or call. Send it after a Voice Server Update with p2p: true.
| Field | Type | Description |
|---|---|---|
| guild_id? | ?snowflake | The guild with the voice channel, where null or omitted selects the direct message and group direct message call context |
| channel_id | snowflake | The voice channel or call channel both connections are in |
| to | string | The connection_id of the voice state the signal is for |
| data | object | The signalling message, which Squad relays unread |
{ "op": 13, "d": { "guild_id": "1189375284394692608", "channel_id": "1189375284394692610", "to": "b7f3c2a94e1d4c0f", "data": { "type": "offer", "sdp": "v=0..." } }}Squad relays the signal when both the sender and the to connection have a voice state with p2p: true in that channel. Only the target connection’s session gets the Voice Signal. Any other signal is dropped with no event and no close.
Request Guild Members
Заголовок раздела «Request Guild Members»Opcode 8 requests member chunks for one or more guilds.
| Field | Type | Description |
|---|---|---|
| guild_id?1 | snowflake | The ID of the single guild to query |
| guild_ids?1 | array[snowflake] | A non-empty array of the guild IDs to query |
| query?2 | string | The display name prefix to match (default empty string) |
| limit?3 | integer | The result limit (0-100, default 0) |
| user_ids?4 | array[snowflake] | The explicit user IDs to select (at most 100, default empty) |
| presences?5 | boolean | Whether results include presences (default false) |
| nonce? | string | A value of at most 32 bytes echoed in each chunk |
1 guild_id is used only when guild_ids is absent or empty. The nonce is echoed only when the request has one guild
2 Matched case-insensitively against the guild nickname, then the global name, then the username
3 0 with a non-empty query gives 25 results. 0 with an empty query requests the full member list, up to 100,000 entries
4 A non-empty array selects those members and ignores query and limit. More than 100 entries abandons the request
5 Offline and invisible presences are omitted
{ "op": 8, "d": { "guild_id": "1189375284394692608", "query": "ann", "limit": 50, "presences": true, "nonce": "a1b2c3" }}Guilds the session is not connected to are skipped, and a request with no connected guild gets no chunk. A user session needs MANAGE_ROLES, KICK_MEMBERS and BAN_MEMBERS together for a full member list, and the owner and ADMINISTRATOR satisfy that. Without them the request is dropped silently. A bot needs no permission for it.
Squad drops a bot request that lists more than one guild in guild_ids, with no chunk. A bot asking for the full list gets one accepted request per guild every 30 seconds, and another request inside that window gets Rate Limited and no chunk.
Results arrive as Guild Members Chunk pages of at most 1,000 members with chunk_index and chunk_count. Chunks are not replayed on Resume.
Lazy Request
Заголовок раздела «Lazy Request»Opcode 14 sets the per-guild subscriptions that decide member list, typing, sync and thread traffic.
| Field | Type | Description |
|---|---|---|
| subscriptions1 | map[snowflake, guild subscription object] | The subscription options for each guild, keyed by guild ID |
1 Squad applies each guild’s options again when the session connects to that guild later, and keeps options for at most 10 guilds the session isn’t connected to yet
{ "op": 14, "d": { "subscriptions": { "1189375284394692608": { "active": true, "typing": true, "member_list_channels": { "1189375284394692610": [[0, 99]] } } } }}Guild subscription object
Заголовок раздела «Guild subscription object»Structure
Заголовок раздела «Structure»| Field | Type | Description |
|---|---|---|
| active?1 | boolean | Whether the guild is active for this session |
| sync?1 | boolean | Whether the session requests a Guild Sync for the guild |
| typing? | boolean | Whether the guild delivers Typing Start, overriding the active flag |
| member_list_channels?2 | map[snowflake, array[array[integer]]] | The member list windows to subscribe to, keyed by channel ID |
| members? | array[snowflake] | The explicit member IDs to subscribe to (at most 1,000) |
| focused_channel_id?3 | ?snowflake | The channel or public thread a visiting session has open |
1 A non-Boolean value is ignored
2 Each range is [start, end] with start at least 0, end at least start and at most 100,000, and end - start at most 99. Invalid ranges are dropped and each channel keeps its first 10
3 Used only for a guild the session is visiting, where it is the only option applied. Null or an unreadable channel clears it. A visiting session gets messages and reactions only for this channel, and none for the guild’s other channels
A user session is passive in a guild of more than 250 members until active is true for it, unless it is the Identify initial_guild_id, and a passive session gets only some events.
Switching a guild between passive and active sends a Guild Sync unless the session already has one for that guild. Going passive also clears the threads subscription, and the next switch to active syncs again.
A channel gets Guild Member List Update only when you have VIEW_CHANNEL and VIEW_CHANNEL_MEMBERS in it. Thread IDs here subscribe to nothing. Use thread_member_lists. Subscribing a channel to a range drops the session’s member list in any other channel or guild.
Request Guild Counts
Заголовок раздела «Request Guild Counts»Opcode 15 requests the member and online counts for guilds.
| Field | Type | Description |
|---|---|---|
| guild_ids | array[snowflake] | The guild IDs to query, deduplicated and truncated to 100 |
| nonce? | string | A value of 1-64 bytes echoed in the result |
{ "op": 15, "d": { "guild_ids": ["1189375284394692608"], "nonce": "counts-1" }}Guilds the session is not connected to are skipped. Results arrive in one Guild Counts Update, and a guild that does not respond within 2,000 ms is left out.
Request Channel Member Counts
Заголовок раздела «Request Channel Member Counts»Opcode 16 requests the member and online counts for channels in one guild.
| Field | Type | Description |
|---|---|---|
| guild_id | snowflake | The ID of the guild whose channels are queried |
| channel_ids? | array[snowflake] | The channel IDs to query, deduplicated and truncated to 25 |
| channel_id?1 | snowflake | The ID of the single channel to query |
| nonce? | string | A value of 1-64 bytes echoed in the result |
1 Used only when channel_ids is absent or not an array
{ "op": 16, "d": { "guild_id": "1189375284394692608", "channel_ids": ["1189375284394692610"], "nonce": "channel-counts-1" }}An invalid or unconnected guild gives an empty result. Results arrive in one Channel Member Counts Update, and a channel is counted only when it isn’t a thread and you have VIEW_CHANNEL and VIEW_CHANNEL_MEMBERS in it.