How to make a slash command parse multiple arguments?
- Discord.js ver. 13.6.0
- Node.js ver. 16.13.0
I've been wondering if there's a way that I can just have a slash command detect multiple... arguments that it's given, and if the command can have multiple versions.
Say, I have a command called "create", and past the word create, I give it 2 words, then a number, it should detect that the 2 words are "first name" and "last name", but if I give it 3 words, it detects it as "first name", "middle name", and "last name"?
I also ask because I've been using the
"addStringOption"
to the command, making it rather long and tedious for people to write in, as they have to select the option before writing in their option.
The code for the command: https://pastebin.com/7Lamre1V
Code for the command handler, just in case: https://pastebin.com/vCMFAaGjPastebin
const { SlashCommandBuilder } = require("@discordjs/builders");cons...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin
module.exports ={ name: "interactionCreate", async execute (...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
13 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
If you want a command with multiple versions, you should check out subcommands (https://discordjs.guide/slash-commands/advanced-creation.html#subcommands)
However, another viable option would be to make the first and last name required options, and leave the middle name as a non-required option
While I appreciate the answer, it doesn't really clarify a doubt that I still have, in regards to how make sure that the slash command can take multiple arguments, in a manner that's different, and probably more preferable then just using ".addStringOption" to make sure that the slash command registers that string specifically.
you can just call
addStringOption
multiple times
or whatever option type you wishI have
It just feels a tad bit inconvenient.
I was thinking of passing all the strings as arguments, split them and pass the individual strings as the like, but I'm not sure how to do so with a slash command... I've tried to do so before, but I didn't get it to work..
Any help would be apreciated..
I find it a bit tedious since what I want to do is the following, and I apologize since English is a second language for me so I might have a bit of trouble expressing myself:
/create-player [First Name] [optional Middle name] [Last Name] [Age] [Species] [Type] [optional second Type] [Starting Level]
Where after just typing /create-player
, one can just type in a long string with the correct formatting and the command could slice and parse the string correctly.
I'm... not sure if it's a stupid idea compared to the code I've written...
Hm, that is a good idea actually.
but then how do I manage to have it so that the middle name, and the second typing is optional inputsTo make them required, use
<Option>.setRequired(true)
. If you don't set that, they are non-required by default
One thing to note is that you have to have your options in the order where all the required options are first, and all of your non-required options are secondSo, when inputting the data into the command, it'd be:
/create-player [First Name] [Last Name] [Age] [Species] [Type] [Starting Level] [optional Middle name] [optional second Type]
right?That's correct
Like this?
https://pastebin.com/7Lamre1V
Pastebin
const { SlashCommandBuilder } = require("@discordjs/builders");cons...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I've added some extra terms, but I think it'll work.
Your best bet is to try it and see if it looks good in the app
According to the db that I have, it seems to work well!
Made 2 instances, with and without the optional info
It works :D
Now, uh, how does one close a forum that's been resolved? .w.'