Browse Source

Fix move_to related voice state bugs

docs/guide
Imayhaveborkedit 1 year ago
committed by GitHub
parent
commit
a9ff58724b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      discord/gateway.py
  2. 17
      discord/voice_state.py

2
discord/gateway.py

@ -827,7 +827,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

17
discord/voice_state.py

@ -267,26 +267,31 @@ 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 +489,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)
@ -637,3 +645,6 @@ class VoiceConnectionState:
async def _move_to(self, channel: abc.Snowflake) -> None:
await self.voice_client.channel.guild.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) # type: ignore

Loading…
Cancel
Save