diff options
| author | Samlon <stankiewiczgracjan2019@gmail.com> | 2025-08-11 20:23:14 +0200 |
|---|---|---|
| committer | Samlon <stankiewiczgracjan2019@gmail.com> | 2025-08-11 20:23:14 +0200 |
| commit | 2883f34929b1f5227eb80d89eae6c5c24a862fa0 (patch) | |
| tree | 3ed42b7ddfd5182969438797ff0defd409290507 /cogs/vclogs.py | |
| parent | small join.py fix and better vc handling for logs (diff) | |
| download | senator-sperma-2883f34929b1f5227eb80d89eae6c5c24a862fa0.tar.gz senator-sperma-2883f34929b1f5227eb80d89eae6c5c24a862fa0.zip | |
small join.py fix and better vc handling for logs
Diffstat (limited to '')
| -rw-r--r-- | cogs/vclogs.py | 15 |
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 |
