我能否以一种方式发送 args[1] 参数 args[2] 次?

3
我希望我的机器人能够向某人发送args[1]的直接消息,次数是args[2]。 我认为这应该很简单,但迄今为止我还没有找到方法。 这是我目前的代码:
module.exports = {
    name: 'message',
    description: 'message',
    execute(message, args) {    
         
        let recipient = message.mentions.users.first()
        
        if (message.author.id === 'My ID') {
            recipient.send(args[1])
        }       
            if ((!args[1])) return message.channel.send('Please include the message you want to send.')            
            if (isNaN(args[2])) return message.channel.send('Please include how many times you want the message to send.')
    }          
}
1个回答

2
您可以使用一个简单的for循环:
module.exports = {
  name: 'message',
  description: 'message',
  execute(message, args) {
    let recipient = message.mentions.users.first();

    if (!args[1])
      return message.channel.send(
        'Please include the message you want to send.',
      );
    if (isNaN(args[2]))
      return message.channel.send(
        'Please include how many times you want to send the message.',
      );

    if (message.author.id === 'My ID') {
      for (let i = 0; i < args[2]; i++) {
        recipient.send(args[1]);
      }
    }
  },
};

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接