1

I try to make sure that there is a delay between each message that the bot will send with forEach, but I can’t.

I tried several methods that I could find a little on the internet, and even methods available on this site, but I have not managed to set them up.

How do I solve the problem?

bot.on('message', message => {
  if(message.content.startsWith('hm')) {
    let cont = message.content.slice(1).split(" ");
    let args = cont.slice(1);
    let member = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0]);
    message.guild.members.forEach((player) => {
      message.guild.member(player).send(`Test`);
    });
  }
})
Emma
  • 1
  • 9
  • 28
  • 53
Fanfarone
  • 77
  • 5

1 Answers1

-1

I am not sure if it helps but you can use the time lib from python and specify how many second you would like to pause:

# Import time lib
import time

# Create a variable to speficy the seconds to pause
SECONDS_DELAY=10

 if(message.content.startsWith('hm')){
let cont = message.content.slice(1).split(" ")
        let args = cont.slice(1)
        let member = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0])
      message.guild.members.forEach((player) => {
          message.guild.member(player).send(`Test`);

          # set the time sleep with the variable created before   
          time.sleep(SECONDS_DELAY)
});
    }
})