diff options
| author | salmonik <raisersoft@proton.me> | 2026-05-21 17:10:23 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-05-21 17:10:23 +0200 |
| commit | 2e614665e0c62fe572b5af53a2a6be1116d66720 (patch) | |
| tree | dbb48ad5d665a3f3d8c793db30a523264f17bcde /cogs/cron.py | |
| parent | fix naming not resolving things like %20 (diff) | |
| parent | Fix voice reconnect race: reuse VoiceClient instead of destroying it (diff) | |
| download | senator-sperma-2e614665e0c62fe572b5af53a2a6be1116d66720.tar.gz senator-sperma-2e614665e0c62fe572b5af53a2a6be1116d66720.zip | |
Merge pull request 'Voice related fixes, alongside simplifying assistant' (#5) from dev into main
Reviewed-on: https://codeberg.org/salmonik/senator-sperma/pulls/5
Diffstat (limited to '')
| -rw-r--r-- | cogs/cron.py | 26 |
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}" |
