防止机器人断开用户与正常语音通道的连接?
Preventing bot from disconnecting users from normal voice channels?
我正在尝试让我的 discord 机器人断开连接到 AFK 频道的用户。一切都很好,除了它会尝试断开刚刚进入谈话频道的用户,而不仅仅是当你转移到 AFK 频道时。我必须设置权限以不允许机器人移动或断开与这些频道的连接,因此它会不断拉起缺少权限。希望它忽略那些其他语音频道。
我不确定如何排除语音通道所以我尝试了
if discord.VoiceChannel.id == id:
return
无济于事。我已经尝试将机器人设置为不通过 discord 看到这些频道,但它仍然可以看到并且仍然试图断开人们的连接。
@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
指的是成员最近的语音频道,none如果他们不在一个,那么当他们去AFK频道时,after = discord.VoiceState.afk
它会断开连接。我解释错了吗?我显然遗漏了一些东西
阅读文档怎么样? Here it is
我的想法是你可以做到
if discord.VoiceClient.channel.id == id:
return
但我觉得这是错误的。
从API开始,on_voice_state_update
会给你三样东西:
- 改变语音状态的
member
VoiceState
之前成员做了某事。
VoiceState
在成员做了某事之后。
而 "did something" 的意思是:
- 成员加入语音频道
- 成员退出语音频道
- 该成员将自己静音或耳聋。
- 该成员被其他人弄聋或静音了。
(也就是 API 的字面意思)
您要查找的是 VoiceState
after the change has occured. And in the API, it states that VoiceState
has a property called 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
我正在尝试让我的 discord 机器人断开连接到 AFK 频道的用户。一切都很好,除了它会尝试断开刚刚进入谈话频道的用户,而不仅仅是当你转移到 AFK 频道时。我必须设置权限以不允许机器人移动或断开与这些频道的连接,因此它会不断拉起缺少权限。希望它忽略那些其他语音频道。
我不确定如何排除语音通道所以我尝试了
if discord.VoiceChannel.id == id:
return
无济于事。我已经尝试将机器人设置为不通过 discord 看到这些频道,但它仍然可以看到并且仍然试图断开人们的连接。
@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
指的是成员最近的语音频道,none如果他们不在一个,那么当他们去AFK频道时,after = discord.VoiceState.afk
它会断开连接。我解释错了吗?我显然遗漏了一些东西
阅读文档怎么样? Here it is 我的想法是你可以做到
if discord.VoiceClient.channel.id == id:
return
但我觉得这是错误的。
从API开始,on_voice_state_update
会给你三样东西:
- 改变语音状态的
member
VoiceState
之前成员做了某事。VoiceState
在成员做了某事之后。
而 "did something" 的意思是:
- 成员加入语音频道
- 成员退出语音频道
- 该成员将自己静音或耳聋。
- 该成员被其他人弄聋或静音了。
(也就是 API 的字面意思)
您要查找的是 VoiceState
after the change has occured. And in the API, it states that VoiceState
has a property called 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