我想更改我的不一致机器人状态

时间:2020-07-19 16:23:18

标签: javascript node.js discord discord.js

我想让我的不一致bot状态每10秒更改一次,从“监视x服务器”到“监视x用户”,这是我的代码。

client.once('ready', () => {
  console.log("Conectat ca si: " + client.user.tag);
  client.user.setActivity(`${client.guilds.cache.size} servere | .help`, {
    type: "WATCHING",
    }, 60000);
});

1 个答案:

答案 0 :(得分:0)

client.on("ready", () => {
    let currentActivity = 0;
    let maxActivity = 1;

    setInterval(async () => {
        currentActivity++;
        if (currentActivity > maxActivity) {currentActivity = 0};
        switch(currentActivity) {
            case 0:
                client.user.setActivity(`${client.guilds.cache.size} servers.`, {type: "WATCHING"})
                break;
            case 1:
                client.user.setActivity(`${client.users.cache.size} users.`, {type: "WATCHING"})
                break;
        };
    }, 10000);
});