Discord.py bot中断mp3

2024-09-26 18:02:41 发布

您现在位置:Python中文网/ 问答频道 /正文

由于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()
        

Tags: 文件clientmessageischannel机器人awaitmp3
1条回答
网友
1楼 · 发布于 2024-09-26 18:02:41
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()

现在它开始工作了,谢谢你的回答

相关问题 更多 >

    热门问题