From 40daa849baee39c8885b4ffe738550fa0bbb7b58 Mon Sep 17 00:00:00 2001 From: CDE90 Date: Sat, 4 Mar 2023 18:01:49 +0000 Subject: [PATCH] Fix TTS erroring? --- cogs/tts.py | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/cogs/tts.py b/cogs/tts.py index 3c507d2..3588063 100644 --- a/cogs/tts.py +++ b/cogs/tts.py @@ -101,28 +101,30 @@ async def play( vc: Optional[discord.VoiceClient] = None - try: - vc = await interaction.user.voice.channel.connect() - except discord.ClientException: - for c in self.client.voice_clients: - if not isinstance(c, discord.VoiceClient): - continue - if ( - c.channel == interaction.user.voice.channel - and c.is_playing() - ): - return await interaction.response.send_message( - "Please wait for the current TTS message to finish" - ) - elif c.channel == interaction.user.voice.channel: - vc = c - break - - if not isinstance(vc, discord.VoiceClient): + for x in self.client.voice_clients: + if not isinstance(x, discord.VoiceClient): + continue + if x.guild.id == interaction.guild.id: + vc = x + break + + if vc and vc.is_playing(): return await interaction.response.send_message( - "Unknown error occured. Pleast try again." + "Please wait for the current TTS message to finish." ) + if not isinstance(vc, discord.VoiceClient): + try: + vc = await interaction.user.voice.channel.connect() + except discord.ClientException: + return await interaction.response.send_message( + "Cannot connect to a voice channel I'm already in." + ) + except discord.HTTPException: + return await interaction.response.send_message( + "Failed to connect to the voice channel." + ) + embed = discord.Embed( color=discord.Color.green(), title="**Reading Message**",