From bae5f317d15044761dc1495efe38bdea35e7beb9 Mon Sep 17 00:00:00 2001 From: quentin Date: Fri, 20 Jun 2025 20:24:35 -0500 Subject: [PATCH] Delay bot disconnect for 5 min --- scr/modules/TMC/commands/player.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scr/modules/TMC/commands/player.py b/scr/modules/TMC/commands/player.py index 254f102..d26d578 100644 --- a/scr/modules/TMC/commands/player.py +++ b/scr/modules/TMC/commands/player.py @@ -44,6 +44,7 @@ class Queue: self.bot = bot self.cleanup_callback = cleanup_callback self.seek = False + self.disconnect_task: Optional[asyncio.Task] = None def is_playing(self): return self.voice_client and self.voice_client.is_playing() @@ -63,8 +64,17 @@ class Queue: else: self.current = None - await asyncio.sleep(5) # Give some time for the buffer to finish before disconnecting. - await self.cleanup_callback() + if self.disconnect_task: + self.disconnect_task.cancel() + + self.disconnect_task = asyncio.create_task(self._delayed_disconnect()) + + async def _delayed_disconnect(self): + try: + await asyncio.sleep(300) + await self.cleanup_callback() + except asyncio.CancelledError: + pass def _play(self, track: Track): source = FFmpegPCMAudio(track.url, **FFMPEG_OPTIONS) @@ -116,6 +126,10 @@ class Player(commands.Cog): self.queues[ctx.guild] = queue queue.voice_client = await voice.channel.connect() + if queue.disconnect_task: + queue.disconnect_task.cancel() + queue.disconnect_task = None + # Enqueue the track track = Track(audio_url, title) queue.tracks.append(track)