How to see which option was triggered from an interaction

I have a slash command where there are two options (say a and b). a has three choices say 1,2,3 b has no additional options I know that i can get the choice that was triggered from option a by doing let cmd = interaction.options.get("a"); but how can i know which option was triggered ? also can i add a option to a choice ? i.e. if user selects option a with choice 1 i want them to pass a integer value too
20 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Idris
Idris2y ago
interaction.options.getString("cmdtype") will you give the choice's value
Febkosq8
Febkosq82y ago
i need to know what option was made not the choice
Idris
Idris2y ago
wdym by « was made » ? you just get options
Febkosq8
Febkosq82y ago
refer my image, i need to know if the user took cmdType or kickguild
Idris
Idris2y ago
I just told you cmdtype is just option name if someone choose a thing between choices you'll get a choice's value interaction.options.getString("cmdtype") == "kickGuild" for example
Febkosq8
Febkosq82y ago
my old image was not correct for this question see this
Febkosq8
Febkosq82y ago
Febkosq8
Febkosq82y ago
Febkosq8
Febkosq82y ago
i need to mention the option name here which i dont know what the user chose
Febkosq8
Febkosq82y ago
like here
Febkosq8
Febkosq82y ago
i need to see if the option they chose was cmdtype or kickguild
Squid
Squid2y ago
Get the values for both options using getString/getInteger If they did not input a value for the option, that function will return null However, because nothing is stopping them from entering a value for both options, you should use subcommands for guildlist and kickguild instead of just making them normal options
Febkosq8
Febkosq82y ago
so there is not inbuilt way to know which option was triggered
Squid
Squid2y ago
Also, you cannot make it so if someone enters something for one option, a different option becomes required However, you can make two subcommands: one with the extra option, and one without
Febkosq8
Febkosq82y ago
console.log(interaction.options); gets me this
Febkosq8
Febkosq82y ago
got it
Squid
Squid2y ago
If you get a string option that's not "triggered," getString() will return null That's how you can tell if they triggered it or not
Febkosq8
Febkosq82y ago
understood Found out something console.log(interaction.options.data[0].name); will get me the name of the option that was triggered
Febkosq8
Febkosq82y ago
Want results from more Discord servers?
Add your server
More Posts