diff options
| author | salmonik <raisersoft@proton.me> | 2026-04-08 16:21:49 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-04-08 16:21:49 +0200 |
| commit | 2339a21639e79ba7f6ecb334d65d1857b2490733 (patch) | |
| tree | a83e8699f9458a0a7ca9d16579277f5aa39bbe85 | |
| parent | make it work + visual changes (diff) | |
| download | senator-sperma-2339a21639e79ba7f6ecb334d65d1857b2490733.tar.gz senator-sperma-2339a21639e79ba7f6ecb334d65d1857b2490733.zip | |
"fix" voice management
| -rw-r--r-- | cogs/vclogs.py | 26 | ||||
| -rw-r--r-- | cogs/voice.py | 15 |
2 files changed, 36 insertions, 5 deletions
diff --git a/cogs/vclogs.py b/cogs/vclogs.py index 0d80ae7..477aa1c 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py | |||
| @@ -78,15 +78,31 @@ class VcLogs(commands.Cog): | |||
| 78 | logger.info("saving file") | 78 | logger.info("saving file") |
| 79 | tts.save(tts_file) | 79 | tts.save(tts_file) |
| 80 | 80 | ||
| 81 | voice_client = await voice_mgr.get_voice_client(channel.guild) | 81 | # Get voice status using our new method |
| 82 | volume = get_volume() | 82 | voice_status = await voice_mgr.get_voice_status(channel.guild) |
| 83 | 83 | voice_client = voice_status[0] if voice_status else None | |
| 84 | if voice_client is None: | 84 | is_connected = voice_status[1] if voice_status else False |
| 85 | is_playing = voice_status[2] if voice_status else False | ||
| 86 | |||
| 87 | # Ensure we have a connected voice client | ||
| 88 | if not is_connected: | ||
| 85 | voice_client = await voice_mgr.join_channel(channel) | 89 | voice_client = await voice_mgr.join_channel(channel) |
| 90 | # Update status after joining | ||
| 91 | voice_status = await voice_mgr.get_voice_status(channel.guild) | ||
| 92 | voice_client = voice_status[0] if voice_status else None | ||
| 93 | is_connected = voice_status[1] if voice_status else False | ||
| 94 | is_playing = voice_status[2] if voice_status else False | ||
| 95 | |||
| 96 | if not is_connected or voice_client is None: | ||
| 97 | logger.error("Failed to join voice channel") | ||
| 98 | if os.path.exists(tts_file): | ||
| 99 | os.remove(tts_file) | ||
| 100 | return | ||
| 86 | 101 | ||
| 102 | volume = get_volume() | ||
| 87 | logger.info(f"connected: {voice_client}") | 103 | logger.info(f"connected: {voice_client}") |
| 88 | 104 | ||
| 89 | if voice_client and not voice_client.is_playing(): | 105 | if voice_client and not is_playing: |
| 90 | logger.info("preparing to play audio") | 106 | logger.info("preparing to play audio") |
| 91 | audio_source = discord.FFmpegPCMAudio(tts_file, options=f'-filter:a "volume={volume}"') | 107 | audio_source = discord.FFmpegPCMAudio(tts_file, options=f'-filter:a "volume={volume}"') |
| 92 | voice_client.play(audio_source) | 108 | voice_client.play(audio_source) |
diff --git a/cogs/voice.py b/cogs/voice.py index 8ee3699..316de7b 100644 --- a/cogs/voice.py +++ b/cogs/voice.py | |||
| @@ -69,6 +69,21 @@ class VoiceManager: | |||
| 69 | """Get existing voice client for a guild.""" | 69 | """Get existing voice client for a guild.""" |
| 70 | return discord.utils.get(self.bot.voice_clients, guild=guild) | 70 | return discord.utils.get(self.bot.voice_clients, guild=guild) |
| 71 | 71 | ||
| 72 | async def get_voice_status(self, guild): | ||
| 73 | """Get voice client status including connection and playback state. | ||
| 74 | |||
| 75 | Returns: | ||
| 76 | tuple: (voice_client, is_connected, is_playing) or (None, False, False) if no client | ||
| 77 | """ | ||
| 78 | voice_client = await self.get_voice_client(guild) | ||
| 79 | if voice_client is None: | ||
| 80 | return None, False, False | ||
| 81 | |||
| 82 | is_connected = voice_client.is_connected() | ||
| 83 | is_playing = voice_client.is_playing() if is_connected else False | ||
| 84 | |||
| 85 | return voice_client, is_connected, is_playing | ||
| 86 | |||
| 72 | async def play_audio(self, channel, audio_source, volume=1.0): | 87 | async def play_audio(self, channel, audio_source, volume=1.0): |
| 73 | """Play audio in a voice channel.""" | 88 | """Play audio in a voice channel.""" |
| 74 | voice_client = await self.join_channel(channel) | 89 | voice_client = await self.join_channel(channel) |
