python - 如果机器人与 VC 断开连接,如何让机器人重新连接?
问题描述
@client.command()
async def join(ctx):
voiceChannel = discord.utils.get(ctx.guild.voice_channels, name='General')
await voiceChannel.connect()
如果有人断开机器人(不移动)但只是断开连接,我该如何重新连接?
解决方案
如果机器人与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:
参考:
推荐阅读
- reactjs - 如何将函数传递给组件?
- excel - 为什么调用函数时会出现错误 424?
- r - 图表在函数之外创建,而不是在函数内部创建
- json - 在 Swift 中解码类别数组的正确方法是什么
- python - 日志记录 - 始终包含类属性
- java - 使用 BufferedImage 和 ImageIO 进行图像转换
- java - Jackson 属性中的 Spring-boot 和多态性
- github - How to find out when empty repository was created?
- c# - HttpClient GET 请求
- php - 如何以正确的方式发布 cUrl 请求?