From d61e6dbab69d5a1bfdc1d298d5df885984c5e95b Mon Sep 17 00:00:00 2001 From: AlTech98 Date: Fri, 3 Sep 2021 14:12:44 +0200 Subject: Make the user leave the current channel before joining one in another guild --- gateway/src/opcodes/VoiceStateUpdate.ts | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gateway') diff --git a/gateway/src/opcodes/VoiceStateUpdate.ts b/gateway/src/opcodes/VoiceStateUpdate.ts index 10808c10..668508fd 100644 --- a/gateway/src/opcodes/VoiceStateUpdate.ts +++ b/gateway/src/opcodes/VoiceStateUpdate.ts @@ -22,6 +22,15 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) { return; } + //If a user change voice channel between guild we should send a left event first + if (voiceState.guild_id !== body.guild_id) { + await emitEvent({ + event: "VOICE_STATE_UPDATE", + data: { ...voiceState, channel_id: null }, + guild_id: voiceState.guild_id, + }) + } + //The event send by Discord's client on channel leave has both guild_id and channel_id as null if (body.guild_id === null) body.guild_id = voiceState.guild_id; voiceState.assign(body); -- cgit 1.4.1