【问题标题】:Discord.js bot's presence isn't working fineDiscord.js 机器人的存在无法正常工作
【发布时间】:2021-07-05 16:53:35
【问题描述】:

我想让我的存在将来自 json 文件的订单数量显示到机器人的存在中,但它不显示任何内容,也不会在控制台中显示任何错误

const fsn = require("fs-nextra");
module.exports = {
    name: 'ready',
    once: true,
    execute(client) {
      fsn.readJSON("./orders.json").then((orderDB) => {
            let amount = 0;
            for (let x in orderDB) {
              amount++;
               client.user.setPresence({
        status: 'online',
        activity: {
            name: `${amount} orders | .help`,
            type: "WATCHING"
        }       
        })
             }
      });  
        console.log(`Ready! Logged in as ${client.user.tag}`);
    },
};

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    您忘记在循环后设置“}”。我改了你下面代码中的错误:

    const fsn = require("fs-nextra");
    module.exports = {
        name: 'ready',
        once: true,
        execute(client) {
            fsn.readJSON("./orders.json").then((orderDB) => {
                let amount = 0;
                for (let x in orderDB) {
                    amount++;
                }
                client.user.setPresence({
                    status: 'online',
                    activity: {
                        name: `${amount} orders | .help`,
                        type: "WATCHING"
                    }
                })
            });
            console.log(`Ready! Logged in as ${client.user.tag}`);
        },
    };
    

    【讨论】:

    • 哦,谢谢,我有一个小问题,每次 json 文件中有新订单时会更新吗?
    • 否,因为您只是在机器人的就绪事件上触发此事件。因此,每次机器人重新启动并调用就绪事件时,它们的存在状态都会更新
    猜你喜欢
    • 2020-10-29
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 2018-03-27
    • 2023-03-08
    相关资源
    最近更新 更多