From 5675dfd20b24f1e0eef06b11d9ec41a894d3a5bf Mon Sep 17 00:00:00 2001 From: salmonik Date: Tue, 28 Apr 2026 20:05:36 +0200 Subject: multitude of changes. but primarly, use db for all data. Signed-off-by: salmonik --- cogs/voice.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'cogs/voice.py') diff --git a/cogs/voice.py b/cogs/voice.py index 319bb16..046c2a8 100644 --- a/cogs/voice.py +++ b/cogs/voice.py @@ -45,6 +45,7 @@ class VoiceManager: return voice_client except Exception as e: logger.error(f"Failed to move voice client: {e}") + logger.info("Disconnecting after failed move attempt") try: await voice_client.disconnect() except Exception: @@ -55,6 +56,25 @@ class VoiceManager: voice_client = await channel.connect(timeout=30.0, reconnect=False) logger.info(f"Connected to voice channel: {channel}") return voice_client + except discord.ClientException as e: + if "Already connected" in str(e): + logger.warning(f"Stale voice state detected, forcing disconnect and reconnect: {e}") + voice_client = discord.utils.get(self.bot.voice_clients, guild=guild) + if voice_client: + try: + await voice_client.disconnect() + except Exception: + pass + await asyncio.sleep(0.3) + try: + voice_client = await channel.connect(timeout=30.0, reconnect=False) + logger.info(f"Reconnected to voice channel: {channel}") + return voice_client + except Exception as e2: + logger.error(f"Failed to reconnect after stale cleanup: {e2}") + return None + logger.error(f"Failed to connect to voice channel: {e}") + return None except Exception as e: logger.error(f"Failed to connect to voice channel: {e}") return None @@ -113,6 +133,7 @@ class VoiceManager: voice_client = await self.get_voice_client(guild) if voice_client: voice_client.stop() + logger.info("stop() called - disconnecting from voice") await voice_client.disconnect() logger.info(f"Stopped and disconnected from guild {guild}") @@ -174,6 +195,7 @@ class Voice(commands.Cog): if voice_client and not voice_client.is_connected(): try: + logger.info("Voice client exists but not connected - disconnecting stale client") await voice_client.disconnect() except Exception: pass -- cgit v1.2.3