aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/cron.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cogs/cron.py26
1 files changed, 10 insertions, 16 deletions
diff --git a/cogs/cron.py b/cogs/cron.py
index aad43d2..ee88085 100644
--- a/cogs/cron.py
+++ b/cogs/cron.py
@@ -145,29 +145,23 @@ class Cron(commands.Cog):
145 145
146 if isinstance(channel, discord.VoiceChannel): 146 if isinstance(channel, discord.VoiceChannel):
147 voice_mgr = get_voice_manager(self.bot) 147 voice_mgr = get_voice_manager(self.bot)
148 voice_client = await voice_mgr.join_channel(channel)
149 if not voice_client:
150 if channel.guild.system_channel:
151 await channel.guild.system_channel.send(
152 "Nie udano się połączyć z kanałem głosowym"
153 )
154 return
155 148
156 try: 149 try:
157 audio_source = discord.FFmpegPCMAudio(audio_url) 150 audio_source = discord.FFmpegPCMAudio(audio_url)
158 voice_client.play(audio_source) 151 success = await voice_mgr.play_source(channel, audio_source)
159 152
160 while voice_client.is_playing(): 153 if success:
161 await asyncio.sleep(1) 154 logger.info(f"Finished playing audio: {audio_url}")
155 else:
156 raise Exception("Playback failed")
162 157
163 logger.info("Audio playback finished normally - disconnecting") 158 await voice_mgr.disconnect(channel.guild)
164 await voice_client.disconnect()
165 logger.info(f"Finished playing audio: {audio_url}")
166 except Exception as e: 159 except Exception as e:
167 logger.error(f"Error playing audio: {e}") 160 logger.error(f"Error playing audio: {e}")
168 if voice_client.is_connected(): 161 try:
169 logger.info("Audio playback failed - disconnecting") 162 await voice_mgr.disconnect(channel.guild)
170 await voice_client.disconnect() 163 except Exception:
164 pass
171 if channel.guild.system_channel: 165 if channel.guild.system_channel:
172 await channel.guild.system_channel.send( 166 await channel.guild.system_channel.send(
173 f"Błąd podczas odgrywania audio: {audio_url}" 167 f"Błąd podczas odgrywania audio: {audio_url}"