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

183
Visualizações
discord.js v13 - Add option to choice

I want to use options in choice in slash commands. Let me explain:

/info user

User writes this slash command. The "user" is choice in this command. If we write "user" as the choice, it should give an user option. Like:

/info server

If we write like that, it'll just execute the command, because the server does not need anymore info.

/info user

But if we write like that, it'll ask for an user. You can add user options by writing .addUserOption, but I should add it to choice, I don't know how to do it. Here is my code:

const { SlashCommandBuilder } = require("@discordjs/builders")

module.exports = {
    data: new SlashCommandBuilder()
        .setName("info")
        .setDescription("Get info about X! (usage: /info X)")
        .addStringOption((o) =>
            o
                .setName("choice")
                .setDescription("What info do you want to get?")
                .setRequired(true)
                .addChoice('Server', 'server')
                .addChoice('User', 'user')
                .addUserOption((o) =>
                    o
                        .setName("user")
                        .setDescription("What user do you want to get info about?")
                        .setRequired(true)
                    )
                .addChoice('Bot', 'bot')
            ),
    async execute(i) {
        if (i.options.getString("choice") == 'server') {
            i.reply({
                content: `server`,
                emphemeral: true
            })
        }
        if (i.options.getString("choice") == 'user') {
            i.reply({
                content: `user`,
                emphemeral: true
            })
        }
        if (i.options.getString("choice") == 'bot') {
            i.reply({
                content: `bot`,
                emphemeral: true
            })
        }
    }
}

That's what I tried. It gives me an error. How can I do it? Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

.addStringOption() has its own choices. After .addStringOption(), you unindent it so it is on the same line where that started, then add .addUserOption() with its own choices.

// ...
    .addStringOption(() => {
        // ...
    })
        .addChoice("Foo", "foo")
        .addChoice("Bar", "bar")
    .addUserOption(() => {
        // ...
    })
        .addChoice("<@1234567890>")
        .addChoice("<@1234567890>")
about 4 years ago · Juan Pablo Isaza 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