From b9471513eada8fd55e686d139432cfe9a0d87388 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Tue, 14 Mar 2023 07:18:23 +0000 Subject: [PATCH] Include ssrc parameter when sending a SPEAKING payload As it is a required parameter. Don't unnecessarily send a second SPEAKING payload after connecting to voice We do need to send a SPEAKING payload in order to set our SSRC value after connecting to voice, yet that can be with a `state` of 0 (SpeakingState.none). There is no reason to send 2 packets; one marking ourselves as speaking, and then not speaking. --- discord/gateway.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/discord/gateway.py b/discord/gateway.py index faca4b920..3de52a0ce 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -1014,6 +1014,7 @@ class DiscordVoiceWebSocket: 'd': { 'speaking': int(state), 'delay': 0, + 'ssrc': self._connection.ssrc, }, } @@ -1089,7 +1090,11 @@ class DiscordVoiceWebSocket: async def load_secret_key(self, data: Dict[str, Any]) -> None: _log.debug('Received secret key for voice connection.') self.secret_key = self._connection.secret_key = data['secret_key'] - await self.speak() + + # Send a speak command with the "not speaking" state. + # This also tells Discord our SSRC value, which Discord requires + # before sending any voice data (and is the real reason why we + # call this here). await self.speak(SpeakingState.none) async def poll_event(self) -> None: