Detect if a bot account goes offline/online(检测机器人帐户是否离线/在线)
问题描述
我正在使用 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.
这篇关于检测机器人帐户是否离线/在线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检测机器人帐户是否离线/在线


基础教程推荐
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01