如何使用setTimeout函数JS发出ping命令

时间:2019-10-23 23:12:26

标签: javascript discord.js

    const m1 = await message.channel.send("Calculating ping (47%)").then(setTimeout(5000))
    const m2 = await m1.edit("Calculating ping (80%)").then(setTimeout(4000))
    const m3 = await m2.edit(`Finished Calculating ping! API Latency is ${Math.round(bot.ping)}ms`);

    m1
    m2
    m3

我如何做到这一点,以便当该人使用ping命令时,然后在某个时间编辑为渐进式ping过程,例如“计算ping 47%”,然后转到“计算ping 90%”,然后转到“完成计算ping !,这是ping毫秒”

1 个答案:

答案 0 :(得分:0)

像这样的内部使用

    module.exports = {
    name: "ping",
    category: "info",
    description: "Returns latency and API ping",
    run: async (client, message, args) => {

        const msg = await message.channel.send(`? Pinging....`);

        msg.edit(`? Pong!
        Latency is ${Math.floor((msg.editedTimestamp || msg.createdTimestamp) - (message.editedTimestamp || message.createdTimestamp))}ms
        API Latency is ${Math.round(client.ping)}ms`);
    }

}

ping消息在15毫秒内不会花费很多时间,因此这种方式更好