Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
DiscordJS v14 Slash commands option depends on option

I want to make a Discord slash command where you need to select one choice and then another choice.

But depending of what choice is made in the first place (in choice 1) the options/values in the choice 2 are changing.

Is that possible?

Example: /command choice1 choice2

If I select "A" in choice1 I get "One" and "Two" as choices in choice. But when I select "B" in choice1, I will get "Three" and "Four" as choice2 options.

Best Regards,

Paul

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Choices are predetermined values, that are set when the command is registered, and cannot be changed afterwords.

The way to dynamically change option choices is through "autocomplete," or depending on the situation, "subcommands" could also work.

In order to set up autocomplete to change based on other values, you'd need to access interaction.options.get(choice2) for choice1 and interaction.options.get(choice1) for choice2 (the interaction here would be an AutocompleteInteraction)

Here's an example:

client.on('interactionCreate', async interaction => {
    if (!interaction.isAutocomplete()) return;

    if (interaction.commandName === 'command') {
        const focusedOption = interaction.options.getFocused(true);
        let choices;

        if (focusedOption.name === 'option1') {
            choices = ["A", "B"];
        }

        if (focusedOption.name === 'option2') {
            let option1 = interaction.options.get('option1')?.value;
            if (option1 === "A") {
                choices = ["One", "Two"];
            }
            else if (option1 === "B") {
                choices = ["Three", "Four"];
            }
            else {
                choices = ["One", "Two", "Three", "Four"];
            }
        }

        const filtered = choices.filter(choice => choice.startsWith(focusedOption.value));
        await interaction.respond(
            filtered.map(choice => ({ name: choice, value: choice })),
        );
    }
});

As with all interactions, you must respond within 3 seconds. But you cannot defer AutocompleteInteractions, so I'd recommend .catch()ing the interaction response in case of errors.

See here for more info:

[1] https://discordjs.guide/interactions/autocomplete.html

[2] https://discord.js.org/#/docs/main/main/class/AutocompleteInteraction

almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!