So I'm trying to create my bot and I want there to be a command which adds information to a sqlite database
https://gyazo.com/6961a05dc2d6aeca6683b59f888c2e82
if (command === "addplayer") {
message.delete()
let [name, crew, rank, weapon, df, talent, profession, other] = args;
if(!name) return message.author.send("Name argument is required!");
let id = name.toLowerCase();
if(!crew) {let crew = "Blank";}
if(!rank) {let rank = "Blank";}
if(!weapon) {let weapon = "Blank";}
if(!df) {let df = "Blank";}
if(!talent) {let talent = "Blank";}
if(!profession) {let profession = "Blank";}
if(!other) {let other = "Blank";}
sql.run("INSERT INTO players (id, Name, Crew, Rank, Weapon, DF,
Talent, Profession, Other) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", [id,
name, crew, rank, weapon, df, talent, profession, other]);
return
}
All I want to know really is how to add like a space key to the arguments so I can do
>addplayer info with space, more info, even more, and so on
And when I do the other command it lists it out like this:
Info1: info with space
Info2: more info
Info3: even more
Info4: and so on
Ok, so using your sample command as an example, let's say someone enters this, and you want to know how to handle it:
I assume you have already figured out how to check the command prefix, and split the command from the args, but I'll show how I would do that below.
The key here, is you use
.split(',')
to turn the args string into an array, split on','
character (and use.trim()
to clear out whitespace from each element, THEN you assign all of your variables to the args array.The final
...other]
is used to catch any remaining arguments - so if your text'Other information Goes here'
had commas, all of those extra arguments would get stored (as an array) in theother
variable. If you want to put them all back together, you can use.join(',')
to separate them by comma.Let me know if you have any questions!
I've just decided to go with multiple commands like
>edit EXAMPLE
and then doing something like>editname EXAMPLE1
setting the name to EXAMPLE1 instead of EXAMPLE