Tuesday 30 May 2017

How can I take varying amount of arguments?

So I have this Discord bot with a command to add a link/password combo. Currently it can only accept two arguments, but I have users who would like to paste in a whole list of links/passwords and have them all entered at once.

This is my code now:

if (command === "add"){
message.delete();
let link = message.content.split(" ")[1];
let answer = message.content.split(" ")[2];
  if (!link || !answer){
  user.send('Please be sure to enter a link **and** its corresponding answer.');
  }
lockers.push({"link":link,"answer":answer});
fs.writeFile('./serverLockers.json', JSON.stringify(serverLockers), (err) => {if(err) console.error(err)});
return;
}

The message in this case would be string that is "[command] [link] [answer]".

I want to be able to do something like "[command] [link] [answer],[link] [answer],[link] [answer]"

How can I change this to add multiple combos at once? It will have to know how many combinations were entered And the amount of combinations entered will always vary



via John Doe

No comments:

Post a Comment