Skip to content

Commit

Permalink
Fix WebSocketGatewayClientExt::send_chunk_guild to not get disconne…
Browse files Browse the repository at this point in the history
…cted by Discord's gateway (#1200)

* Send the guild ID as a string instead of an array when requesting members list from Discord

In API version 8, Discord's gateway expects a guild ID as a string instead of as an array when requesting guild members. Sending as an array causes the payload to be invalid and, therefore, the gateway closes the connection

* Set query even if no filter was applied by the user

Either the query or the user ID array is required when sending a member list request to Discord, according to their API v8 documentation
  • Loading branch information
lapin-b committed Jan 26, 2021
1 parent 2854e6b commit 2f835a3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/gateway/ws_client_ext.rs
Expand Up @@ -64,14 +64,14 @@ impl WebSocketGatewayClientExt for WsStream {
let mut payload = json!({
"op": OpCode::GetGuildMembers.num(),
"d": {
"guild_id": [guild_id.as_ref().0],
"guild_id": guild_id.as_ref().0.to_string(),
"limit": limit.unwrap_or(0),
"nonce": nonce.unwrap_or(""),
},
});

match filter {
ChunkGuildFilter::None => {},
ChunkGuildFilter::None => payload["d"]["query"] = json!(""),
ChunkGuildFilter::Query(query) => payload["d"]["query"] = json!(query),
ChunkGuildFilter::UserIds(user_ids) => {
let ids = user_ids.iter().map(|x| x.0).collect::<Vec<u64>>();
Expand Down

0 comments on commit 2f835a3

Please sign in to comment.