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•3y ago
Message Not Public
Sign In & Join Server To View
interaction.options.getString("cmdtype")
will you give the choice's valuei need to know what option was made
not the choice
wdym by « was made » ?
you just get options
refer my image, i need to know if the user took cmdType or kickguild
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 examplemy old image was not correct for this question
see this
i need to mention the option name here which i dont know what the user chose
like here
i need to see if the option they chose was cmdtype or kickguild
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
so there is not inbuilt way to know which option was triggered
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
console.log(interaction.options); gets me this
got it
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
understood
Found out something
console.log(interaction.options.data[0].name);
will get me the name of the option that was triggered