如果机器人与 VC 断开连接,如何让机器人重新连接?

时间:2021-04-26 14:35:21

标签: python discord.py

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

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

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

1 个答案:

答案 0 :(得分:0)

使用 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

参考文献: