make player.destroy useful

This commit is contained in:
vveeps 2021-10-28 17:58:59 +03:00
parent f4ffbcd5b8
commit b72258cb60
1 changed files with 4 additions and 6 deletions

View File

@ -202,26 +202,24 @@ class Player(VoiceProtocol):
await self._node.send(op="stop", guildId=str(self.guild.id)) await self._node.send(op="stop", guildId=str(self.guild.id))
async def disconnect(self, *, force: bool = False): async def disconnect(self, *, force: bool = False):
"""Disconnects the player from voice and handles internal state cleanup.""" """Disconnects the player from voice."""
try: try:
await self.guild.change_voice_state(channel=None) await self.guild.change_voice_state(channel=None)
finally: finally:
self.cleanup() self.cleanup()
self._is_connected = False self._is_connected = False
self.channel = None self.channel = None
del self._node._players[self.guild.id]
async def destroy(self): async def destroy(self):
"""Disconnects the player and sends a call to destroy the player on Lavalink's end.""" """Disconnects and destroys the player, and runs internal cleanup."""
try: try:
await self.disconnect() await self.disconnect()
except AttributeError: except AttributeError:
# 'NoneType' has no attribute '_get_voice_client_key' raised by self.cleanup() -> # 'NoneType' has no attribute '_get_voice_client_key' raised by self.cleanup() ->
# assume we're already disconnected and cleaned up # assume we're already disconnected and cleaned up
assert self.channel is None \ assert self.channel is None and not self.is_connected
and not self.is_connected \
and self.guild.id not in self._node._players
del self._node._players[self.guild.id]
await self._node.send(op="destroy", guildId=str(self.guild.id)) await self._node.send(op="destroy", guildId=str(self.guild.id))
async def play( async def play(