首页 > 解决方案 > Discord.py bot 中断 mp3

问题描述

由于 mp3 文件较长,机器人停止,尝试将比特率更改为低。这是代码

@client.command(pass_context=True)
async def bock(ctx):
    await ctx.message.delete()
    author = ctx.message.author
    channel = author.voice.channel
    voice = get(client.voice_clients, guild=ctx.guild)
    if voice and voice.is_connected():
        await voice.move_to(channel)
    else:
        voice = await channel.connect()
        voice.play(discord.FFmpegPCMAudio(executable=FFMexec, source="bock.mp3"))#, options = "-analyzeduration 1000000000 -i"
        while voice.is_playing():
            time.sleep(0.5)
        await voice.disconnect()
        

标签: pythondiscordbots

解决方案


async def bock(ctx):
    await ctx.message.delete()
    author = ctx.message.author
    channel = author.voice.channel
    voice = get(client.voice_clients, guild=ctx.guild)
    if voice and voice.is_connected():
        await voice.move_to(channel)
    else:
        voice = await channel.connect()
        voice.play(discord.FFmpegPCMAudio(executable=FFMexec, source="bock.mp3"))#, options = "-analyzeduration 1000000000 -i"
        while voice.is_playing():
            await asyncio.sleep(5) # bot was frozen to death before
        await voice.disconnect()

现在可以用了,谢谢解答


推荐阅读