From 2883f34929b1f5227eb80d89eae6c5c24a862fa0 Mon Sep 17 00:00:00 2001 From: Samlon Date: Mon, 11 Aug 2025 20:23:14 +0200 Subject: small join.py fix and better vc handling for logs --- cogs/vclogs.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'cogs') diff --git a/cogs/vclogs.py b/cogs/vclogs.py index a9672ac..64c356d 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py @@ -50,11 +50,22 @@ class VcLogs(commands.Cog): tts = gTTS(text=text, lang='pl') tts.save('temp_tts.mp3') - # Connect to the voice channel if not already connected + # Get the voice client for the guild voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild) + + # Handle connection state if not voice_client or not voice_client.is_connected(): - voice_client = await channel.connect() + # If no voice client or not connected, create a new connection + try: + voice_client = await channel.connect() + except discord.ClientException as e: + if 'already connected' in str(e).lower(): + # If already connected, find the existing connection + voice_client = next((vc for vc in self.bot.voice_clients if vc.guild == channel.guild), None) + else: + raise elif voice_client.channel != channel: + # If connected to a different channel, move to the new one await voice_client.move_to(channel) # Play the TTS audio -- cgit v1.2.3