检测机器人帐户是否离线/在线

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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Auto-reply to direct messages(自动回复直接消息)
Play local music files using djs v13(使用 djs v13 播放本地音乐文件)
Making a bot delete its own message after a timeout(让机器人在超时后删除自己的消息)
How do I upload a custom emoji to my discord bot(如何将自定义表情符号上传到我的不和谐机器人)
Discord.js meme command with meme subreddit returns image as 403 forbidden(带有 meme subreddit 的 Discord.js meme 命令将图像返回为 403 禁止)
How to get snekfetch results into an object?(如何将 snekfetch 结果放入对象中?)