Paulo Pires
Paulo Pires

Reputation: 45

Sending a message 5 minutes after a command

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

Answers (3)

Tina the Cyclops
Tina the Cyclops

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

Shubham Gupta
Shubham Gupta

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

Shammoo
Shammoo

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

Related Questions