0

I basically want to run something at all times. I need it to run at least once a minute. I know how to run something whenever a message is sent. This is my method:

const Discord = require('discord.js');
const bot = new Discord.Client();
bot.on('message', message => {
    //code here
});

How would I go about running a block of code at least once every minute?

joker876
  • 45
  • 1
  • 6

1 Answers1

1

you can create a function and use bot.setInterval() to run it every x amounts of milliseconds, it's best you initialise it in the ready event.

const doSomething = () => {
  // Do something
}

bot.on('ready', () => {
  bot.setInterval(doSomething(), 5000) // Runs every 5 seconds
})
Syntle
  • 5,168
  • 3
  • 13
  • 34