我正试图让我的不和谐机器人断开与转移到AFK频道的用户的连接。除了尝试断开仅进入通话频道的用户,而不仅仅是当您移至AFK频道时,所有其他功能都可以正常运行。我必须设置权限以不允许漫游器移动或与这些通道断开连接,因此它会不断拉高Missing权限。希望忽略其他语音通道。
我不确定如何排除语音通道,所以我尝试了
if discord.VoiceChannel.id == id:
return
无济于事。我尝试将漫游器设置为不通过不和谐看到这些频道,但仍然可以,并且仍然试图断开人们的联系。
@client.event
async def on_voice_state_update(member = discord.Member, before = discord.VoiceState.channel, after = discord.VoiceState.afk):
await member.move_to(channel = None, reason = None)
我猜这是基本的东西,但不确定如何忽略其他渠道。
我以为API表示before = discord.VoiceState.channel
指的是一个成员最近的语音通道,如果不在一个成员中则没有任何通道,那么当他们进入AFK通道时,after = discord.VoiceState.afk
会断开连接。我是在解释错吗?我显然缺少了一些东西
答案 0 :(得分:2)
在API中,on_voice_state_update
将为您提供三件事:
member
VoiceState
之前做过一些事情。VoiceState
之后。“做些什么”的意思是:
(也就是API所说的)
您要查找的是VoiceState
之后的 。并且在API中,它声明VoiceState
具有名为afk
的属性,该属性检查成员是否在afk通道中。
您的代码应如下所示:
@client.event
async def on_voice_state_update(member, before, after):
# If the user moved to the afk channel.
if after.afk:
# Do something about the user in afk channel.
### Use the codes below if you want to check if the user moved to a channel of the ID:
if after.channel is None:
# The user just simply left the channel.
# (Aka he did not switch to another voice channel.)
elif after.channel.id == ID_OF_CHANNEL_HERE:
# Do something about the user that just joined the channel with the respective ID
答案 1 :(得分:0)