【发布时间】:2021-05-24 18:54:13
【问题描述】:
所以我制作了一个不和谐机器人,当它发现自己在通话中时,它就会断开与语音频道的连接。我就是这样做的:(注意,我使用的是齿轮)
@commands.Cog.listener("on_voice_state_update")
async def voiceStateUpdate(self, member, before, after):
voiceClient = discord.utils.get(self.bot.voice_clients, guild = member.guild) # Bot "voice_client"
if voiceClient.channel != None:
if len(voiceClient.channel.members) == 1:
await voiceClient.disconnect() # Disconnect
这很好用。但是,如果我在 restart 我的代码时忘记离开通话,我会在我的机器人重新启动时留在频道中(如预期的那样)。当我断开自己的通话时,问题就来了。机器人停留在里面,只输出这个错误:(line 37, if voiceClient.channel != None:) AttributeError: 'NoneType' object has no attribute 'channel'
也许这是因为它不知道它还在频道中? 我很困惑...谢谢你的时间。 :-)
【问题讨论】:
标签: python discord discord.py bots