I am coding a discord bot. Discord is a social platform with a chat, and you can code bots there.
In order to trigger bot commands, the bot reads every single message sent to the chat. It's sent to him as a string.
By using this: var args = msg.content.split(' ');
the bot separates every single word into an array. Now, I can do this: if (args[0] === '!command') { //code }
My bot will keep track of League of Legends players. I want to be able to put the name and add a reason for the tracking. All of that will go into a database. At first, it seems simple, I can just do this:
if (args[0] === '!command') {
var player = args[1];
var reason = args[2];
}
Now, if I send !command player1 reasons
the bot will get it right.
The issue is, in League of Legends, having spaces in your nickname is allowed. At the same time, one single word for the reason might fall short. If you tried to do this: !command "player one" reasons
the bot wouldn't get player one
as the args[1], instead, "player
would be args[1] and one"
would be args[2]. At the same time, reasons
would now be args[3] instead of args[2].
Is there a simple way to tell javascript to ignore spaces inside quotation marks so it doesn't split the string there?
I could use a different character to split the string, but writing a command like !command-player-reasons there
feels weird and a patch instead of an actual solution.