繁体   English   中英

当 discord.py 机器人断开连接时清除队列

[英]Clear queue when discord.py bot gets disconnected

当 bot 与 vc 断开连接时,我需要清除队列。 像那样。

我知道我必须使用on_voice_state_update ,但我不知道该怎么做。 曾尝试自己做,但在状态之前之后陷入困境。 请帮忙

    @bot.event
    async def on_voice_state_update(member, before, after):
        if before.voice is None and after.voice is not None:
            disconnect()

好的,这是完整的答案

@bot.event
async def on_voice_state_update(member, before, after):
    if before.channel is not None and after.channel is None and member.bot == True:
        guild=member.guild
        vc: wavelink.Player = guild.voice_client
        await vc.disconnect()
        vc.queue.clear()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM