Rich Presence with Minecraft 玩家数量

Rich Presence with Minecraft player count

我是初学者,我想知道如何在 Rich Presence 中设置 Minecraft 服务器上的玩家数量。 我发现了如何处理下面的代码,但我想将其改编为允许您每 x 秒修改一次 Rich Presence 的脚本。

提前谢谢你, 此致

我在Rich Presence中显示玩家数量的函数: https://pastebin.com/7BpcLb9J

我当前的代码每秒更改一次:

bot.on('ready', async () => {
setInterval(function() {
    let status = statuses[Math.floor(Math.random()*statuses.length)];
    bot.user.setPresence({
        status: "dnd",
        game: {
            name: status,
            type: "WATCHING"
        }
    });
}, 2500)
let statuses = ['firsttext', 'secondtext'];

给你

let currentStatus = false;
var url = 'http://mcapi.us/server/status?ip=' + botconfig.mcIP + '&port=' + botconfig.mcPort;
bot.on('ready', async () => {

    setInterval(() => {
        shuffleStatus(currentStatus);
    }, 2500)


});

const shuffleStatus = (index) => {
    if (index) {
        getServerStatus().then((status) => {
            bot.user.setActivity(status, {
                type: 'PLAYING'
            })
        });
    } else {
        bot.user.setStatus('online')
        bot.user.setActivity('status 2', {
            type: 'PLAYING'
        })
    }
    currentStatus = !currentStatus;
}

const getServerStatus = () => {
    var serverStatus = new Promise(function (resolve, reject) {
        request(url, function (err, response, body) {
            if (err) {
                reject(err);
            }
            body = JSON.parse(body);
            let status = 'Server offline';
            if (body.online) {
                if ((body.motd == "&cWe are under maintenance.") || (body.players.now >= body.players.max)) {
                    bot.user.setStatus('idle')
                        .catch(console.error);
                } else {
                    bot.user.setStatus('online')
                        .catch(console.error);
                }
                if (body.players.now) {
                    status = `${body.players.now} of ${body.players.max}`;
                } else {
                    status = `0 of ${body.players.max}`
                }
            }
            resolve(status);
        });
    })
    return serverStatus;
}