Skip to content

Commit

Permalink
Add force keyword to Node.destroy and player.destroy/disconnect.
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Feb 25, 2021
1 parent 156e047 commit 05e582e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions wavelink/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ def set_hook(self, func) -> None:

self.hook = func

async def destroy(self) -> None:
async def destroy(self, *, force: bool = False) -> None:
"""Destroy the node and all it's players."""
players = self.players.copy()

for player in players.values():
await player.destroy()
await player.destroy(force=force)

try:
self._websocket._task.cancel()
Expand Down
16 changes: 12 additions & 4 deletions wavelink/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,16 @@ async def connect(self, channel_id: int):
await self._get_shard_socket(guild.shard_id).voice_state(self.guild_id, str(channel_id))
__log__.info(f'PLAYER | Connected to voice channel:: {self.channel_id}')

async def disconnect(self) -> None:
async def disconnect(self, *, force: bool = False) -> None:
"""|coro|
Disconnect from a Discord Voice Channel.
"""
guild = self.bot.get_guild(self.guild_id)
if not guild and force is True:
self.channel_id = None
return

if not guild:
raise InvalidIDProvided(f'No guild found for id <{self.guild_id}>')

Expand Down Expand Up @@ -333,16 +337,20 @@ async def stop(self) -> None:
__log__.debug(f'PLAYER | Current track stopped:: {str(self.current)} ({self.channel_id})')
self.current = None

async def destroy(self) -> None:
async def destroy(self, *, force: bool = False) -> None:
"""|coro|
Stop the player, and remove any internal references to it.
"""
await self.stop()
await self.disconnect()
await self.disconnect(force=force)

await self.node._send(op='destroy', guildId=str(self.guild_id))
del self.node.players[self.guild_id]

try:
del self.node.players[self.guild_id]
except KeyError:
pass

async def set_eq(self, equalizer: Equalizer) -> None:
"""|coro|
Expand Down

0 comments on commit 05e582e

Please sign in to comment.