Discord py How to make the bot leave voice channel after the mp3 file is finished?
@client.command(pass_context=True) async def ea(ctx): if ctx.author.voice: channel = ctx.message.author.voice.channel voice = await channel.connect() source = FFmpegPCMAudio("./mp3/ea.mp3") player = voice.play(source) else: await ctx.send("")
1 Answer
while voice.is_playing(): await asyncio.sleep(.1) await voice.disconnect()
This is what I have been using. While Voice is playing it sleeps for a small amount of time. Once whatever is playing is over, it disconnects.
https://discordpy.readthedocs.io/en/stable/api.html#discord.VoiceClient
0ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobmlsZmp%2FcoCOnaCsm5%2BnsW682GafqK9dqbxuucCknGasmJp6o7vTZqOemaaaere7yJycZpuYlruvsctmmJ%2Bslad6tbTEZqSpa12btq2xjKKqZp6Zo7a0tMQ%3D