So on the discordjs guide it shows that you can add choices in a slash command. But there is no function explained on how to get the selected choice in an interaction.
Here is the example from discordjs.guide:
But there is no explanation on how to call them in interaction or the reply. Here is the URL of the replying to slash commands ( https://discordjs.guide/interactions/replying-to-slash-commands.html) There is no explanation whatsoever.
So how do I call choices in the interaction.
I can call sub commands like this:
But just no explanation on option choices.
Does someone know how I can call choices in for example If the option choice is enable then send enable if the option choice is disable then send disable
You can get the chosen option with CommandInteraction.options
. Depending on the type of option, you can use a different method. In the picture of the guide, they use a string option, so CommandInteraction.options.getString()
is used here
const chosenString = interaction.options.getString("option-name")
If you would like all the possible choices, use CommandInteraction.command
. This gives an ApplicationCommand
which has the options
property. You can get the choices
there (from one the array elements)
const choices = interaction.command.options[0].choices // get choices of first option