Reputation: 45
So im trying to do my discord bot send a message 5 minutes after someone send a command, but when someone use the command it start sending the message every minute, thats the code
client.on('message', function(message) {
if (message.content === "!command") {
var interval = setInterval (function () {
client.channels.get("493228844896092162")
.send("123")
.catch(console.error);
}, 1 * 5000);
}
});
Upvotes: 2
Views: 1010
Reputation: 43
I'd code it like this:
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);
}
});
Upvotes: 0
Reputation: 2646
Your interval seems to be incorrect. setInterval expects interval to be in milliseconds.
1 * 5000 -> 5sec
You need to update that to
5 * 60 * 1000 -> 5 mins
Upvotes: 1
Reputation: 1103
setInterval
takes the arguments of a function and a set number of milliseconds on which to trigger.
The correct interval would be
setInterval(function(){}, 5 * 60000)
This is 5x60 seconds
Upvotes: 0