From 8d0a52ab34563beab33be2dfb207da0e03a8fe32 Mon Sep 17 00:00:00 2001 From: Samlon Date: Wed, 13 Aug 2025 14:59:22 +0200 Subject: prevent discord from complaining and bot does not leave vc after playing --- cogs/tts.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'cogs/tts.py') diff --git a/cogs/tts.py b/cogs/tts.py index c00259f..7461a1f 100644 --- a/cogs/tts.py +++ b/cogs/tts.py @@ -1,6 +1,6 @@ import datetime import os - +import json import discord from discord.ext import commands from gtts import gTTS @@ -20,6 +20,13 @@ class TTS(commands.Cog): tts = gTTS(text=text, lang='pl') tts.save('tts.mp3') + if os.path.exists('settings.json'): + with open('settings.json') as f: + data = json.load(f) + volume = data['volume'] + else: + logger.error("settings.json not found") + if output == "file": await ctx.respond(file=discord.File('tts.mp3')) logger.info("TTS file sent") @@ -42,7 +49,7 @@ class TTS(commands.Cog): await voice_client.move_to(channel) # Play the TTS audio if not voice_client.is_playing(): - audio_source = discord.FFmpegPCMAudio('tts.mp3', options='-filter:a "volume=6"') + audio_source = discord.FFmpegPCMAudio('tts.mp3', options=f'-filter:a "volume={volume}"') logger.info("TTS audio played") voice_client.play(audio_source) # Wait for playback to finish @@ -55,5 +62,4 @@ class TTS(commands.Cog): os.remove('tts.mp3') def setup(bot): - bot.add_cog(TTS(bot)) -1 \ No newline at end of file + bot.add_cog(TTS(bot)) \ No newline at end of file -- cgit v1.2.3