代码之家  ›  专栏  ›  技术社区  ›  ipsa scientia potestas

让discord bot只使用一个命令发送多条消息

  •  3
  • ipsa scientia potestas  · 技术社区  · 7 年前

    !赞扬

    所有其他命令都正确运行(下面我放了一个这样的命令, !救世主 ,例如),但是 !赞扬

    我希望它能在循环中迭代,每次都发送一条消息,就像你从一个 for

    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;
        }
      }
    });
    
    2 回复  |  直到 7 年前
        1
  •  1
  •   manveti    7 年前

    看看你身体的状况 for i === 5 )。只要这是真的,循环就会执行。但是,您可以通过指定 i = 1 ,并且1不等于5,即使对于较大的值1也是如此。

        2
  •  0
  •   James Conway    7 年前

    bot.sendMessage