首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >记录用户在线状态discord.js

记录用户在线状态discord.js
EN

Stack Overflow用户
提问于 2020-12-16 07:41:58
回答 1查看 304关注 0票数 0

我正在尝试为我的名为Timer Bot的机器人记录状态。我希望它能在他上线和下线的时候提醒每个人。这是我正在使用的脚本-

代码语言:javascript
复制
client.on('presenceUpdate', (oldPresence, newPresence) => {
    let member = newPresence.member;
    // User id of the user you're tracking status.
    if (member.id === '603517534720753686') {
        if (oldPresence.status !== newPresence.status) {
            // Your specific channel to send a message in.
            let channel = member.guild.channels.cache.get('788547135234375712');
            // You can also use member.guild.channels.resolve('<channelId>');

            let text = "";

            if (newPresence.status === "online") {
                text = "**Hello @everyone, Timer Bot is now online! Thank you for your patience.**";
            } else if (newPresence.status === "offline") {
                text = "**@everyone Due to issues, Timer Bot is currently offline. We apologize for the inconvenience.**";
            }
            // etc...

            channel.send(text);
        }
    }
});

由于某些原因,它不能工作。有人知道为什么吗?谢谢,Brian.#1111

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-16 07:45:49

您需要启用在线状态意图,然后在登录时将其传递给客户端。

代码语言:javascript
复制
new Discord.Client({ws:{intents: [Intents.FLAGS.GUILD_PRESENCES]}});

来源:https://discord.js.org/#/docs/main/stable/class/Intents?scrollTo=s-FLAGS https://discord.com/developers/applications/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65315270

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档