Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda