Wavelink
Wavelink copied to clipboard
Connect, Disconnect, and Move To methods don't accurately report the result
The player tends to think that it is a voice channel when it isn't (reproduce by manually disconnecting inside of Discord) or say that it was able to connect/move to a voice channel even if it wasn't (reproduce by having it connect to a channel that it does not have perms to connect to).
Proposal: Re-write the methods in the player class to work something along the lines of the methods below, where it checks the result afterwards to see if it is the expected result.
async def connect(self, *, timeout: float, reconnect: bool) -> None:
await self.guild.change_voice_state(channel=self.channel, self_deaf=True)
if self.user.id in [m.id for m in self.channel.members]:
self._connected = True
else:
self._connected = False
self.channel = None
raise asyncio.TimeoutError
async def disconnect(self, *, force: bool = False) -> None:
try:
await self.guild.change_voice_state(channel=None)
self._connected = False
self.channel = None
finally:
with contextlib.suppress(ValueError):
self.node._players.remove(self)
self.cleanup()
async def move_to(self, channel: VoiceChannel) -> None:
await self.guild.change_voice_state(channel=channel)
if self.user.id in [m.id for m in channel.members]:
self._connected = True
self.channel = channel
else:
self._connected = False
self.channel = None
raise asyncio.TimeoutError
def is_connected(self):
if not self.channel:
return False
if self.user.id in [m.id for m in self.channel.members]:
return True
return False