aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cogs/vclogs.py15
1 files changed, 13 insertions, 2 deletions
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):
50 tts = gTTS(text=text, lang='pl') 50 tts = gTTS(text=text, lang='pl')
51 tts.save('temp_tts.mp3') 51 tts.save('temp_tts.mp3')
52 52
53 # Connect to the voice channel if not already connected 53 # Get the voice client for the guild
54 voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild) 54 voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild)
55
56 # Handle connection state
55 if not voice_client or not voice_client.is_connected(): 57 if not voice_client or not voice_client.is_connected():
56 voice_client = await channel.connect() 58 # If no voice client or not connected, create a new connection
59 try:
60 voice_client = await channel.connect()
61 except discord.ClientException as e:
62 if 'already connected' in str(e).lower():
63 # If already connected, find the existing connection
64 voice_client = next((vc for vc in self.bot.voice_clients if vc.guild == channel.guild), None)
65 else:
66 raise
57 elif voice_client.channel != channel: 67 elif voice_client.channel != channel:
68 # If connected to a different channel, move to the new one
58 await voice_client.move_to(channel) 69 await voice_client.move_to(channel)
59 70
60 # Play the TTS audio 71 # Play the TTS audio