From 0e204c80a48bfcdd8a1b0b6e8f66e34f07bfe25d Mon Sep 17 00:00:00 2001 From: Oliver Wilkes Date: Sun, 4 Jun 2023 01:20:50 +0100 Subject: [PATCH] feat(player): destroy in disconnect (#89) --- mafic/player.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/mafic/player.py b/mafic/player.py index 2988209..f483441 100644 --- a/mafic/player.py +++ b/mafic/player.py @@ -4,6 +4,7 @@ from __future__ import annotations import asyncio +import warnings from asyncio import Event from collections import OrderedDict from functools import reduce @@ -457,6 +458,14 @@ async def disconnect(self, *, force: bool = False) -> None: if self.client.is_closed(): return + _log.debug( + "Disconnecting player and destroying client.", + extra={"guild": self._guild_id}, + ) + if self._node is not None: + self._node.remove_player(self.guild.id) + await self._node.destroy(guild_id=self.guild.id) + try: _log.debug( "Disconnecting from voice channel.", @@ -529,21 +538,14 @@ async def transfer_to(self, node: Node[ClientT]) -> None: await old_node.destroy(guild_id=self.guild.id) - async def destroy(self) -> None: - """Destroy the player. - - This will disconnect the player and remove it from the node. - """ - _log.debug( - "Disconnecting player and destroying client.", - extra={"guild": self._guild_id}, + async def destroy(self) -> None: # noqa: D102 + warnings.warn( + "Player.destroy is deprecated and will be removed in 3.0.0, " + "use .disconnect instead.", + DeprecationWarning, ) await self.disconnect() - if self._node is not None: - self._node.remove_player(self.guild.id) - await self._node.destroy(guild_id=self.guild.id) - async def fetch_tracks( self, query: str, search_type: SearchType | str = SearchType.YOUTUBE ) -> list[Track] | Playlist | None: