【问题标题】:Discord py How to make the bot leave voice channel after the mp3 file is finished?Discord py 如何让 bot 在 mp3 文件完成后离开语音频道?
【发布时间】:2021-12-24 01:07:49
【问题描述】:

Discord py mp3文件播放完后如何让bot离开语音频道?

@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("")

【问题讨论】:

    标签: python


    【解决方案1】:
    while voice.is_playing():
         await asyncio.sleep(.1)
    await voice.disconnect() 
    

    这是我一直在使用的。在 Voice 播放时,它会休眠一小段时间。一旦播放结束,它就会断开连接。

    https://discordpy.readthedocs.io/en/stable/api.html#discord.VoiceClient

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-29
      • 2022-01-26
      • 2020-07-14
      • 2020-04-28
      • 1970-01-01
      • 1970-01-01
      • 2020-11-04
      • 1970-01-01
      相关资源
      最近更新 更多