WolfTM
WolfTM

Reputation: 45

DiscordJS V13 Slash Command Choices

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: image here 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

Upvotes: 3

Views: 13795

Answers (1)

MrMythical
MrMythical

Reputation: 9041

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

Upvotes: 4

Related Questions