Like the title I need to play a gtts file into a voice channel what is the easiest way to do this? I am using python 3.7. Here is my code so far:
@client.command(name="repeat")
async def repeat(context):
import gtts, ffmpeg
from discord.ext import commands
# grab the user who sent the command
user = context.message.author
voice_channel = user.voice.voice_channel
channel = None
# only play music if user is in a voice channel
if voice_channel != None:
await ctx.send(f"What do you want to say, type cancel to cancel:")
def check(msg):
return msg.author == ctx.author and msg.channel == ctx.channel
try:
msg = await client.wait_for("message", check=check, timeout=120)
except asyncio.TimeoutError:
await ctx.send("Sorry, you didn't reply in time!")
if(msg.content == 'cancel'):
return
tts = gtts.gTTS(str(msg.content), lang="en")
tts.save("text.mp3")
# grab user's voice channel
channel = voice_channel.name
await client.say('User is in channel: '+ channel)
# create StreamPlayer
vc = await client.join_voice_channel(voice_channel)
player = vc.create_ffmpeg_player('text.mp3', after=lambda: print('done'))
player.start()
while not player.is_done():
await asyncio.sleep(1)
# disconnect after the player has finished
player.stop()
await vc.disconnect()
else:
await client.say('User is not in a channel.')
I am still new to making bots on discord so my code looks like a dumpster fire, I am currently working on fixing/compacting my code. once again I am using python 3.7