Skip to content

Commit

Permalink
feat(player): destroy in disconnect (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
ooliver1 committed Jun 4, 2023
1 parent 339cd4c commit 0e204c8
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions mafic/player.py
Expand Up @@ -4,6 +4,7 @@
from __future__ import annotations

import asyncio
import warnings
from asyncio import Event
from collections import OrderedDict
from functools import reduce
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0e204c8

Please sign in to comment.