mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-16 18:59:09 +00:00
Fix bad voice state when moving to a voice channel without permissions
This commit is contained in:
parent
ebe2661f7d
commit
e1aa6cc264
@ -355,8 +355,7 @@ class VoiceClient(VoiceProtocol):
|
|||||||
asyncio.TimeoutError
|
asyncio.TimeoutError
|
||||||
The move did not complete in time, but may still be ongoing.
|
The move did not complete in time, but may still be ongoing.
|
||||||
"""
|
"""
|
||||||
await self._connection.move_to(channel)
|
await self._connection.move_to(channel, timeout)
|
||||||
await self._connection.wait_async(timeout)
|
|
||||||
|
|
||||||
def is_connected(self) -> bool:
|
def is_connected(self) -> bool:
|
||||||
"""Indicates if the voice client is connected to voice."""
|
"""Indicates if the voice client is connected to voice."""
|
||||||
|
@ -459,13 +459,25 @@ class VoiceConnectionState:
|
|||||||
if self.socket:
|
if self.socket:
|
||||||
self.socket.close()
|
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:
|
if channel is None:
|
||||||
await self.disconnect()
|
await self.disconnect()
|
||||||
return
|
return
|
||||||
|
|
||||||
await self.voice_client.channel.guild.change_voice_state(channel=channel)
|
previous_state = self.state
|
||||||
self.state = ConnectionFlowState.set_guild_voice_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:
|
def wait(self, timeout: Optional[float] = None) -> bool:
|
||||||
return self._connected.wait(timeout)
|
return self._connected.wait(timeout)
|
||||||
@ -594,3 +606,7 @@ class VoiceConnectionState:
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user