Skip to content

Commit

Permalink
Fix bad voice state when moving to a voice channel without permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
imayhaveborkedit committed Oct 1, 2023
1 parent ebe2661 commit e1aa6cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 1 addition & 2 deletions discord/voice_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,7 @@ async def move_to(self, channel: Optional[abc.Snowflake], *, timeout: Optional[f
asyncio.TimeoutError
The move did not complete in time, but may still be ongoing.
"""
await self._connection.move_to(channel)
await self._connection.wait_async(timeout)
await self._connection.move_to(channel, timeout)

def is_connected(self) -> bool:
"""Indicates if the voice client is connected to voice."""
Expand Down
22 changes: 19 additions & 3 deletions discord/voice_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,25 @@ async def soft_disconnect(self, *, with_state: ConnectionFlowState = ConnectionF
if self.socket:
self.socket.close()

async def move_to(self, channel: Optional[abc.Snowflake]) -> None:
async def move_to(self, channel: Optional[abc.Snowflake], timeout: Optional[float]) -> None:
if channel is None:
await self.disconnect()
return

await self.voice_client.channel.guild.change_voice_state(channel=channel)
self.state = ConnectionFlowState.set_guild_voice_state
previous_state = self.state
# this is only an outgoing ws request
# if it fails, nothing happens and nothing changes (besides self.state)
await self._move_to(channel)

last_state = self.state
try:
await self.wait_async(timeout)
except asyncio.TimeoutError:
_log.warning('Timed out trying to move to channel %s in guild %s', channel.id, self.guild.id)
if self.state is last_state:
_log.debug('Reverting to previous state %s', previous_state.name)

self.state = previous_state

def wait(self, timeout: Optional[float] = None) -> bool:
return self._connected.wait(timeout)
Expand Down Expand Up @@ -594,3 +606,7 @@ async def _potential_reconnect(self) -> bool:
return False
else:
return True

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

0 comments on commit e1aa6cc

Please sign in to comment.