检测漫游器帐户是否离线/在线 [英] Detect if a bot account goes offline/online

查看:27
本文介绍了检测漫游器帐户是否离线/在线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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.

启用意向后,请尝试以下操作:

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.

这篇关于检测漫游器帐户是否离线/在线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆