命令后 5 分钟发送消息

Sending a message 5 minutes after a command

所以我正在尝试让我的 discord 机器人在有人发送命令后 5 分钟发送一条消息,但是当有人使用命令时它开始每分钟发送一次消息,这就是代码

client.on('message', function(message) {
    if (message.content === "!command") { 
        var interval = setInterval (function () {
            client.channels.get("493228844896092162")
                .send("123")
                .catch(console.error);
        }, 1 * 5000); 
    }
});

setInterval 接受函数的参数和触发的设定毫秒数。

正确的时间间隔是

setInterval(function(){}, 5 * 60000)

这是 5x60 秒

您的时间间隔似乎不正确。 setInterval 期望间隔以毫秒为单位。

1 * 5000 -> 5sec

您需要将其更新为

5 * 60 * 1000 -> 5 mins

我会这样编码:

client.on('message', function(message) {
    if (message.content === "!command") { 
        var interval = setInterval (function () {
try {
            var meme = client.channels.get("493228844896092162")
                meme.send("123")
                } catch (error) {
console.log(error.stack);
        }, 5 * 60000); 
    }
});