60 秒后刷新嵌入 minecraft 服务器实用程序包 (discord.js v12)

Refresh embed after 60 seconds for minecraft server util packages (discord.js v12)

所以我尝试使用 minecraft-server-util

每 60 秒刷新一次嵌入以查看我的 minecraft 服务器的更新状态
util.status('localhost', 25565, options)
        .then((response) =>{
            let online = response.players.online
            let max = response.players.max
            let motd = response.motd.clean
            let version = response.version.name
            let software = response.version.protocol

            if(version == 'Paper 1.16.5') version = 'Minecraft 1.16.5';

            const onlineEmbed = new Discord.MessageEmbed()
            .setColor('#59ff59')
            .setTitle('Survival Server Status')
            .setDescription('Get Survival Server Status')
            .addFields(
                {name: 'Server Address', value: `localhost`, inline: true},
                {name: 'Online Players', value: `${online}/${max}`, inline: true},
                {name: 'Status', value: ':green_circle: Online', inline: true},
                {name: 'MOTD', value: `${motd}`, inline: true},
                {name: 'Version', value: `${version} `, inline: true}
            )
            .setTimestamp()
            message.channel.send(onlineEmbed).then(msg => {
                msg.delete({ timeout: 60000 }).then(msg => {
                    setInterval(() => {
                        msg.channel.send(onlineEmbed)
                    }, 60000)
                })
            })
        })
        .catch((error) => {
          message.channel.send(new Discord.MessageEmbed()
                        .setColor('#d10000')
                        .setTitle('Survival Server Status')
                        .setDescription('Get Survival Server Status')
                        .addFields(
                            {name: 'Server Address', value: 'localhost', inline: true},
                            {name: 'Online Players', value: `None`, inline: true},
                            {name: 'Status', value: ':red_circle: Offline', inline: true},
                            {name: 'MOTD', value: `None`, inline: true},
                            {name: 'Version', value: `Minecraft 1.16.5`, inline: true}
                        )
                        .setTimestamp()).then(msg => {
                            msg.delete({ timeout: 60000 }).then(msg => {
                                setInterval(() => {
                                    msg.channel.send(new Discord.MessageEmbed()
                                    .setColor('#d10000')
                                    .setTitle('Survival Server Status')
                                    .setDescription('Get Survival Server Status')
                                    .addFields(
                                        {name: 'Server Address', value: 'localhost', inline: true},
                                        {name: 'Online Players', value: `None`, inline: true},
                                        {name: 'Status', value: ':red_circle: Offline', inline: true},
                                        {name: 'MOTD', value: `None`, inline: true},
                                        {name: 'Version', value: `Minecraft 1.16.5`, inline: true}
                                    )
                                    .setTimestamp())
                                })
                            })
                        })
        })

但不是更新状态,而是发送新消息但使用旧状态。谁能帮我解决这个问题?谢谢

你可以使这个函数成为 returns

之外的响应
util.status('localhost', 25565, options)

然后使用回复来编辑消息。

现在编辑消息非常简单。

你可以阅读

const loadEmbed = new Discord.MessageEmbed()
    .setColor('#59ff59')
    .setTitle('Loading...')
var online
var max
var motd
var status
var plrcount
var version
var software
function update() {
    util.status('localhost', 25565, options)
        .then((response) =>{
            online = response.players.online
            max = response.players.max
            motd = response.motd.clean
            plrcount = `${online}/${max}`
            version = response.version.name
            software = response.version.protocol
            status = ":green_circle: Online"
            if(version == 'Paper 1.16.5') version = 'Minecraft 1.16.5';
        }).catch(error) => {
            plrcount = "None"
            motd = "None"
            version = "Minecraft 1.16.5"
            status = ":red_circle: Offline"
        })
}
let msg = message.channel.send(loadEmbed)
setInterval(() => {
    update()
    const onlineEmbed = new Discord.MessageEmbed()
        .setColor('#59ff59')
        .setTitle('Survival Server Status')
        .setDescription('Get Survival Server Status')
        .addFields(
            {name: 'Server Address', value: `localhost`, inline: true},
            {name: 'Online Players', value: plrcount, inline: true},
            {name: 'Status', value: status, inline: true},
            {name: 'MOTD', value: motd, inline: true},
            {name: 'Version', value: version, inline: true}
        )
        .setTimestamp()
    msg.edit(onlineEmbed)
}, 60000)

N.B.: 循环整个函数或整个变量设置,而不仅仅是发送消息!