aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/voice.py
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-04-29 14:47:32 +0200
committersalmonik <raisersoft@proton.me>2026-04-29 14:47:32 +0200
commit8a4352ebb5e15ff4be82a9b4e111c1535aab349e (patch)
tree2c4d5b4b65bdc8308b35c411cffa7f17b1bfeb4d /cogs/voice.py
parentfix: fallback to plaintext if no json is provided for assistant.py (diff)
parentproper context for settings (diff)
downloadsenator-sperma-8a4352ebb5e15ff4be82a9b4e111c1535aab349e.tar.gz
senator-sperma-8a4352ebb5e15ff4be82a9b4e111c1535aab349e.zip
Merge branch 'dev'
Signed-off-by: salmonik <raisersoft@proton.me>
Diffstat (limited to 'cogs/voice.py')
-rw-r--r--cogs/voice.py22
1 files changed, 22 insertions, 0 deletions
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:
45 return voice_client 45 return voice_client
46 except Exception as e: 46 except Exception as e:
47 logger.error(f"Failed to move voice client: {e}") 47 logger.error(f"Failed to move voice client: {e}")
48 logger.info("Disconnecting after failed move attempt")
48 try: 49 try:
49 await voice_client.disconnect() 50 await voice_client.disconnect()
50 except Exception: 51 except Exception:
@@ -55,6 +56,25 @@ class VoiceManager:
55 voice_client = await channel.connect(timeout=30.0, reconnect=False) 56 voice_client = await channel.connect(timeout=30.0, reconnect=False)
56 logger.info(f"Connected to voice channel: {channel}") 57 logger.info(f"Connected to voice channel: {channel}")
57 return voice_client 58 return voice_client
59 except discord.ClientException as e:
60 if "Already connected" in str(e):
61 logger.warning(f"Stale voice state detected, forcing disconnect and reconnect: {e}")
62 voice_client = discord.utils.get(self.bot.voice_clients, guild=guild)
63 if voice_client:
64 try:
65 await voice_client.disconnect()
66 except Exception:
67 pass
68 await asyncio.sleep(0.3)
69 try:
70 voice_client = await channel.connect(timeout=30.0, reconnect=False)
71 logger.info(f"Reconnected to voice channel: {channel}")
72 return voice_client
73 except Exception as e2:
74 logger.error(f"Failed to reconnect after stale cleanup: {e2}")
75 return None
76 logger.error(f"Failed to connect to voice channel: {e}")
77 return None
58 except Exception as e: 78 except Exception as e:
59 logger.error(f"Failed to connect to voice channel: {e}") 79 logger.error(f"Failed to connect to voice channel: {e}")
60 return None 80 return None
@@ -113,6 +133,7 @@ class VoiceManager:
113 voice_client = await self.get_voice_client(guild) 133 voice_client = await self.get_voice_client(guild)
114 if voice_client: 134 if voice_client:
115 voice_client.stop() 135 voice_client.stop()
136 logger.info("stop() called - disconnecting from voice")
116 await voice_client.disconnect() 137 await voice_client.disconnect()
117 logger.info(f"Stopped and disconnected from guild {guild}") 138 logger.info(f"Stopped and disconnected from guild {guild}")
118 139
@@ -174,6 +195,7 @@ class Voice(commands.Cog):
174 195
175 if voice_client and not voice_client.is_connected(): 196 if voice_client and not voice_client.is_connected():
176 try: 197 try:
198 logger.info("Voice client exists but not connected - disconnecting stale client")
177 await voice_client.disconnect() 199 await voice_client.disconnect()
178 except Exception: 200 except Exception:
179 pass 201 pass