让一个不和谐的机器人只用一个命令发送多条消息

Have a discord bot send many messages with only one command

我正在为 discord 制作一个 cultist bot,我希望它发送一条消息,当给出适当的命令时,该消息会重复五次 !praise.

所有其他命令 运行 正确(下面我放了一个这样的命令,例如 !saviour),但是 ! praise 命令从不给出任何输出。

我希望它会遍历循环,每次都发送一条消息,正如您对 for 循环所期望的那样。

是什么阻止了 运行ning 的循环,我该如何修复它?

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;
    }
  }
});

查看 for 循环 (i === 5) 中的条件。只要为真,循环就会执行。但是您通过分配 i = 1 开始循环,并且 1 不等于 5,即使对于 1 的大值也是如此。

要回答标题中的问题,您只需 运行 bot.sendMessage 两次在您的听众中。