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

180
Views
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 answers
Answer question

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 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!