From 245431bf1d5e30836493bf2ebe3d10ad3588f4c5 Mon Sep 17 00:00:00 2001 From: Roxedus Date: Sun, 14 Jun 2020 17:34:33 +0200 Subject: [PATCH] Add leavetimer? Hard to test, as the bug it is intended to fix is hard to reproduce --- cogs/musicevents.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cogs/musicevents.py b/cogs/musicevents.py index 7110505..a5efda4 100644 --- a/cogs/musicevents.py +++ b/cogs/musicevents.py @@ -5,8 +5,9 @@ A cog to separate events from regular music commands # Discord Packages import lavalink import lavalink.events -from discord.ext import commands +from discord.ext import commands, tasks +import asyncio import codecs import yaml @@ -17,6 +18,7 @@ from .utils.mixplayer import MixPlayer class MusicEvents(commands.Cog): def __init__(self, bot): self.bot = bot + self.leave_timer.start() # TODO: maybe only load when Music loads if not hasattr(bot, 'lavalink'): # This ensures the client isn't overwritten during cog reloads. bot.lavalink = lavalink.Client(bot.user.id, player=MixPlayer) @@ -80,6 +82,18 @@ class MusicEvents(commands.Cog): await player.stop() await self.connect_to(guild.id, None) + async def leave_check(self): + if len(self.bot.lavalink.player_manager.players) != 0: + for player_id in self.bot.lavalink.player_manager.players: + await self.check_leave_voice(player_id) + return + return + + @tasks.loop(seconds=10.0) + async def leave_timer(self): + await self.leave_check() + await asyncio.sleep(10) + def setup(bot): bot.add_cog(MusicEvents(bot))