Why is my discord bot not playing any audio when joining VC?

59 Views Asked by At

I'm really new to coding and don't really understand it much but I have been trying to build a bot that will join VC and play audios that are saved as mp3s on my PC, as well as join VC and play Text-to-speech. I am currently using nextcord instead of discord.py to allow for me to use gtts. I am able to have the bot join the VC but it won't play any audio.

Here is the code for the mp3:

@commands.has_role("Bot")
@client.command(pass_context=True)
async def play1(ctx, *, user: nextcord.Member = None):
    if ctx.message.author.voice:
        channel = ctx.message.author.voice.channel
        vc = await channel.connect()
        vc.play(nextcord.FFmpegPCMAudio("audio1.mp3"))
        while vc.is_playing():
            await sleep(1)
        await vc.disconnect()
    if user:
        for member in ctx.author.voice.channel.members:
            if user != member and client.user != member:
                await member.edit(mute=False, deafen=False)

Here is the code for the TTS:

@client.command(name="t")
async def tts(ctx, *args):
    text = " ". join(args)
    user = ctx.message.author
    if user.voice != None:
        try:
            vc = await user.voice.channel.connect()
        except:
            vc = ctx.voice_client

        sound = gTTS(text=text, lang="en", tld='co.in', slow=False)
        sound.save("tts-audio.mp3")

        if vc.is_playing():
            vc.stop()

        source = await nextcord.FFmpegOpusAudio.from_probe("tts-audio.mp3", method="fallback")
        vc.play(source)
        while vc.is_playing():
            await sleep(1)
        await vc.disconnect()
    else:
        await ctx.send("you need to be in a voice chat to run this command")
0

There are 0 best solutions below