Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda