Delay bot disconnect for 5 min

This commit is contained in:
quentin 2025-06-20 20:24:35 -05:00
parent 975ebb5ab4
commit bae5f317d1

View File

@ -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)