机器人在一段时间后编辑自己的消息



我有这段代码,但是,在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
}

在X MS后编辑消息

有一个方便的NPMJS包,你可以使用:延迟

我在这里所做的只是实现消息编辑时的延迟。我建议console.logtime.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");
}

最新更新