Browse Source

Fix move_to related voice state bugs

pull/10109/head
Imayhaveborkedit 1 year ago
committed by dolfies
parent
commit
c1d6b47f38
  1. 2
      discord/gateway.py
  2. 16
      discord/voice_state.py

2
discord/gateway.py

@ -890,7 +890,7 @@ class DiscordVoiceWebSocket:
self.loop: asyncio.AbstractEventLoop = loop
self._keep_alive: Optional[VoiceKeepAliveHandler] = None
self._close_code: Optional[int] = None
self.secret_key: Optional[str] = None
self.secret_key: Optional[List[int]] = None
if hook:
self._hook = hook

16
discord/voice_state.py

@ -267,26 +267,30 @@ class VoiceConnectionState:
return
channel_id = int(channel_id)
self.session_id = data['session_id']
# we got the event while connecting
if self.state in (ConnectionFlowState.set_guild_voice_state, ConnectionFlowState.got_voice_server_update):
if self.state is ConnectionFlowState.set_guild_voice_state:
self.state = ConnectionFlowState.got_voice_state_update
# we moved ourselves
if channel_id != self.voice_client.channel.id:
self._update_voice_channel(channel_id)
else:
self.state = ConnectionFlowState.got_both_voice_updates
return
if self.state is ConnectionFlowState.connected:
self.voice_client.channel = channel_id and self.guild.get_channel(int(channel_id)) # type: ignore
self._update_voice_channel(channel_id)
elif self.state is not ConnectionFlowState.disconnected:
if channel_id != self.voice_client.channel.id:
# For some unfortunate reason we were moved during the connection flow
_log.info('Handling channel move while connecting...')
self.voice_client.channel = channel_id and self.guild.get_channel(int(channel_id)) # type: ignore
self._update_voice_channel(channel_id)
await self.soft_disconnect(with_state=ConnectionFlowState.got_voice_state_update)
await self.connect(
reconnect=self.reconnect,
@ -484,6 +488,9 @@ class VoiceConnectionState:
await self.disconnect()
return
if self.voice_client.channel and channel.id == self.voice_client.channel.id:
return
previous_state = self.state
# this is only an outgoing ws request
# if it fails, nothing happens and nothing changes (besides self.state)
@ -644,3 +651,6 @@ class VoiceConnectionState:
else:
await self.voice_client._state.client.change_voice_state(channel=channel)
self.state = ConnectionFlowState.set_guild_voice_state
def _update_voice_channel(self, channel_id: Optional[int]) -> None:
self.voice_client.channel = channel_id and self.guild.get_channel(channel_id) if self.guild else self.voice_client._state._get_private_channel(channel_id) # type: ignore

Loading…
Cancel
Save