Перейти к содержимому

Client commands

Clients send commands over the Gateway WebSocket as JSON, with an opcode in op and the data in d.

OpcodeCommandResult
1HeartbeatOpcode 11 Heartbeat ACK
2IdentifyReady, opcode 7 from a draining node, a close frame, or no response while the Gateway keeps the Identify waiting
3Presence UpdateNone
4Voice State UpdateVoice State Update and Voice Server Update
6ResumeReplayed Dispatches and Resumed, Invalid Session, or a close frame
8Request Guild MembersGuild Members Chunk
13Voice SignalVoice Signal for the target connection
14Lazy RequestGuild Sync and member list and thread list updates
15Request Guild CountsGuild Counts Update
16Request Channel Member CountsChannel Member Counts Update
28Request Forum UnreadsForum Unreads

Every command counts against the payload budgets.

PayloadClose codeReason
A command other than Heartbeat, Identify and Resume before Identify or Resume4003Not authenticated
No Identify or Resume within one heartbeat interval of Hello4003Not authenticated
More than 64 commands between Identify and Ready, or between Resume and Resumed4008Rate limited
A frame that does not decode to an object4002Decode failed
An object with no op4002Invalid payload
An unknown opcode, once the session is authenticated4001Unknown opcode
A payload with op but no d, other than Identify and Resume4001Unknown opcode
Identify or Resume with no d, or on a session that is already authenticated4005Already 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.

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.

FieldTypeDescription
d?integerThe 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.

Opcode 2 authenticates and creates a new session.

FieldTypeDescription
tokenstringThe account or bot token, with no HTTP authentication prefix
propertiesidentify properties objectThe software and capabilities of the connecting client
presence?1?initial presence objectThe 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?integerA non-negative session flags bitfield (default 0)
initial_guild_id?3?snowflakeThe 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.

FaultClose codeReason
A missing token or properties, or an invalid properties, ignored_events or flags4002Invalid identify payload
A token that isn’t a string of 1 to 256 bytes with at least one visible character4004Invalid token
Malformed shard4010Invalid shard
A bot session with more than 2,500 guilds after the shard filter4011Sharding required
The backend rejects the token4004Invalid token
A non-bot account with 100 live sessions4008Too many sessions
The socket already has a session4005Already authenticated
ValueNameDescription
1 << 1DEBOUNCE_MESSAGE_REACTIONSMerges runs of reactions into Message Reaction Add Many
1 << 2CHANNEL_THREADSThe client can parse thread, forum and media channels
1 << 3GUILD_VISITSThe session receives the guilds the account is visiting

Undefined bits are ignored.

FieldTypeDescription
osstringThe operating system the client runs on
browserstringThe client library identifier
devicestringThe device or application identifier
e2ee_capable?1booleanWhether the client can take part in voice with encrypted call media
mobile?2booleanWhether the session is mobile (default false)
latitude?3number or stringThe client latitude, at most 32 characters as a string
longitude?3number or stringThe 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

FieldTypeDescription
status?1stringThe initial status, one of online, idle, dnd, invisible or offline
afk?booleanWhether the session is away (default false)
mobile?booleanWhether the presence is mobile (default false)
custom_status?2?custom status objectThe 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.

FieldTypeDescription
text??stringThe text of the custom status (1-128 characters)
expires_at?1?ISO8601 timestampThe time the custom status expires
emoji_id?2?snowflakeThe snowflake of the custom emoji
emoji_name?3?stringThe 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.

FieldTypeDescription
tokenstringThe token that owns the retained session
session_idstringThe session ID from Ready
seqintegerThe 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.

ConditionResult
Unknown or expired sessionOpcode 9 with d: false
seq below the replay floorOpcode 9 with d: false
Token does not own the sessionClose code 4004, reason Invalid token
seq is negative, above the session sequence or below the acknowledged oneClose code 4007, reason Invalid sequence
The session can’t be restored right nowClose code 4000, reason Session unavailable
The socket already has a sessionClose code 4005, reason Already authenticated

Opcode 3 replaces the current session presence. Updates over the Presence Update limit are dropped without a close.

FieldTypeDescription
statusstringThe status to publish, one of online, idle, dnd, invisible or offline
afk?booleanWhether the session is away (default false)
mobile?booleanWhether the session is mobile (default false)
custom_status?1?custom status objectThe 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.

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.

FieldTypeDescription
guild_id??snowflakeThe guild with the voice channel, where null selects the direct message and group direct message call context
channel_id??snowflakeThe channel to join or move to, where null leaves the membership
connection_id?1?stringThe existing voice connection this update applies to
self_mute?2booleanWhether the client has muted its microphone (default false)
self_deaf?2booleanWhether the client has deafened its output (default false)
self_video?2booleanWhether the client publishes camera video (default false)
self_stream?3booleanWhether this connection advertises a screenshare track (default false)
is_mobile?2booleanWhether 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 stringThe client latitude, used to pick a voice region
longitude?number or stringThe client longitude, used to pick a voice region
p2p?5booleanWhether 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.

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.

FieldTypeDescription
guild_id??snowflakeThe guild with the voice channel, where null or omitted selects the direct message and group direct message call context
channel_idsnowflakeThe voice channel or call channel both connections are in
tostringThe connection_id of the voice state the signal is for
dataobjectThe 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.

Opcode 8 requests member chunks for one or more guilds.

FieldTypeDescription
guild_id?1snowflakeThe ID of the single guild to query
guild_ids?1array[snowflake]A non-empty array of the guild IDs to query
query?2stringThe display name prefix to match (default empty string)
limit?3integerThe result limit (0-100, default 0)
user_ids?4array[snowflake]The explicit user IDs to select (at most 100, default empty)
presences?5booleanWhether results include presences (default false)
nonce?stringA 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.

Opcode 14 sets the per-guild subscriptions that decide member list, typing, sync and thread traffic.

FieldTypeDescription
subscriptions1map[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]]
}
}
}
}
}
FieldTypeDescription
active?1booleanWhether the guild is active for this session
sync?1booleanWhether the session requests a Guild Sync for the guild
typing?booleanWhether the guild delivers Typing Start, overriding the active flag
member_list_channels?2map[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?snowflakeThe 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.

Opcode 15 requests the member and online counts for guilds.

FieldTypeDescription
guild_idsarray[snowflake]The guild IDs to query, deduplicated and truncated to 100
nonce?stringA 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.

Opcode 16 requests the member and online counts for channels in one guild.

FieldTypeDescription
guild_idsnowflakeThe ID of the guild whose channels are queried
channel_ids?array[snowflake]The channel IDs to query, deduplicated and truncated to 25
channel_id?1snowflakeThe ID of the single channel to query
nonce?stringA 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.