一段时间后,Bot编辑自己的消息

时间:2020-07-21 06:30:36

标签: javascript node.js discord discord.js

我有这段代码,但是,机器人在time.milliseconds * 1000时间之后没有编辑其消息。在这段时间之后,我怎么可能让机器人去编辑其消息?

let timeout = 15000;

if (author !== null && timeout - (Date.now() - author) > 0) {
   let time = ms(timeout - (Date.now() - author));
          
    return await message.channel.send("Cool down in effect").then((msg) = {
        setTimeout(() => msg.edit("Cool down is over"), time.milliseconds * 1000)
    })
}

此外,这就是我登录time

时得到的信息
{
  days: 0,
  hours: 0,
  minutes: 0,
  seconds: 14,
  milliseconds: 324,
  microseconds: 0,
  nanoseconds: 0
}

1 个答案:

答案 0 :(得分:0)

在X MS之后编辑消息

有一个方便的NPMJS软件包,您可以使用:delay

我在这里所做的只是实现消息编辑时的延迟。我建议使用console.logging time.milliseconds * 1000并检查其输出。

const delay = require('delay');

let timeout = 15000;//(15 seconds)

if (author !== null && timeout - (Date.now() - author) > 0) {
   let time = ms(timeout - (Date.now() - author));
     
   const cooldownMessage = await message.channel.send("Cool down in effect");
   await delay(time.milliseconds * 1000);
   cooldownMessage.edit("Cool down is over");
}

如果这有帮助,请确保对答案:D