问题描述
我正在使用 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设计公司网站源码
高端大气html5设计公司网站源码 织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选) 财税代理公司注册代理记账网站织梦模板(带手机端)
财税代理公司注册代理记账网站织梦模板(带手机端) 成人高考自考在职研究生教育机构网站源码(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端) 高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)