我正在使用 presenceUpdate
事件,但是它触发了两次,我被告知它正在发射我与机器人共享的服务器数量.目前我的代码输出 online
两次.我不确定如何让它只输出一次.
I am using the presenceUpdate
event however, it is triggering twice, I am told it is emitting for how many shared servers I have with the bot. Currently my code outputs online
twice. I am not sure on how to get it to output just once.
if (newPresence.userID === botid) {
if (newPresence.status === 'online') {
console.log(newPresence.status); // Should output 'online' currently outputs 'online online'
我注意到这个问题仍未解决,所以我会为您解决.所以上面的答案是正确的,但是,它们都没有说明机器人为此需要的意图.
I noticed that this remained unsolved, so I'll solve it for you. So the answers above are correct, however, none of them states the intents the bot requires for this.
你看,presenceUpdate
不会发出,除非你启用了出席权限网关意图.对于少于 100 个服务器中的机器人,可以通过翻转开关在开发人员门户上进行切换.否则,您需要为不和谐打开一张票以启用存在意图.
You see, presenceUpdate
won't emit unless you have enabled the presence privilege gateway intent. For bots in less than 100 servers, this can be toggled on the developer portal by flipping a switch. Otherwise you need to open a ticket for discord to enable the presence intent.
启用 Intent 后,试试这个:
Once you enable intents, try this:
client.on(`presenceUpdate`,(member)=>{
console.log(`${member.user.username} has updated their presence.`)
})
然后尝试将您的状态更改为 dnd.如果你启用它,你应该看到[您的标签] 更新了他们的存在.
.否则你可能做错了什么.
Then try changing your status to dnd. If you enabled it, you should see
[your tag] has updated their presence.
. Otherwise you may have done something wrong.
这篇关于检测机器人帐户是否离线/在线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!