首页 > 解决方案 > 如果机器人与 VC 断开连接,如何让机器人重新连接?

问题描述

@client.command()
async def join(ctx):
   

    voiceChannel = discord.utils.get(ctx.guild.voice_channels, name='General')
    await voiceChannel.connect()

如果有人断开机器人(不移动)但只是断开连接,我该如何重新连接?

标签: pythondiscord.py

解决方案


如果机器人与on_voice_state_update(member, before, after)这样的语音通道断开连接,您可以获得:

@client.event
async def on_voice_state_update(member, before, after):
    if member.id == client.user.id and after.channel == None and before.channel != None:
        voiceChannel = before.channel
        await voiceChannel.connect()

这需要启用Intents.voice_states

参考:


推荐阅读