ipsa scientia potestas
ipsa scientia potestas

Reputation: 531

Have a discord bot send many messages with only one command

I am making a cultist bot for discord, and I want it to send a message that repeats a message five times when an appropriate command is given !praise.

All the other commands run correctly (below I put one such command, !saviour, as an example), however, the !praise command never gives any output.

I was hoping it would iterate through the loop, sending a message each time, as you would expect from a for loop.

What stops the loop from running and how can I fix it?

bot.on('message', function(user, userID, channelID, message, evt) {
  if (message.substring(0, 1) === '!') {
    let args = message.substring(1).split(' ');
    let cmd = args[0];

    args = args.splice(1);
    switch (cmd) {
      case 'saviour':
        bot.sendMessage({
          to: channelID,
          message: 'Our current lord and saviour is named asghjahero'
        });
        break; //the above case works fine
      case 'praise':
        for (let i = 1; i === 5; i++) {
          bot.sendMessage({
            to: channelID,
            message: 'All Hail!'
          });
        }
        break;
    }
  }
});

Upvotes: 1

Views: 1633

Answers (2)

James Conway
James Conway

Reputation: 349

To answer the question in the title, you just run bot.sendMessage twice in your listener.

Upvotes: 0

manveti
manveti

Reputation: 1711

Take a look at the condition in your for loop (i === 5). The loop will execute as long as that's true. But you start the loop off by assigning i = 1, and 1 is not equal to 5, even for large values of 1.

Upvotes: 1

Related Questions