#How to add choice to slash command?

30 messages · Page 1 of 1 (latest)

vast kelp
#

Hey, I want to add choices to the option named "section", But I don't know how.
Can you guide me?


module.exports = {
    name: "new-staff",
    description: "give role to new staff",
    user: ["ADMINISTRATOR"],
    options: [
        {
            name: "user",
            description: "The user you want to add the role to",
            required: true,
            type: "USER"
        },
        {
            name: "section",
            description: "The user you want to add the role to",
            required: true,
            type: "STRING"
            
        }
    ],
    /**
     *
     * @param {Client} client
     * @param {CommandInteraction} interaction
     * @param {String[]} args
     */
    run: async (client, interaction, args) => {
        const section = interaction.options.getString("section")
        const user = interaction.options.getMember('user');

        if (section === 'mta_roles') {
            const mta_roles = ['1000138410075377706', '1000138410268311563'];

            mta_roles.forEach(async role => {
                let rl = interaction.guild.roles.cache.find(r => r.id == role);
                user.roles.add(rl);
                await wait(500);
            })
            await interaction.reply({ content: ':ballot_box_with_check: Success (MTA)', ephemeral: true });
        } else if (section === 'fivem_roles') {
            const fivem_roles = ['1000138410230558804', '1000138410268311562'];

            fivem_roles.forEach(async role => {
                let rl = interaction.guild.roles.cache.find(r => r.id == role);
                user.roles.add(rl);
                await wait(500);
            })
            await interaction.reply({ content: ':ballot_box_with_check: Success (FIVEM)', ephemeral: true });
        }
    }
};
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

#

node js v 16
discord.js v13.12.0

glossy zinc
#

I mean you did it correctly

vast kelp
#

to the "section" option

glossy zinc
#

Change the type

#

TO

#

Wait

vast kelp
#

tnx

wild furnaceBOT
#

Suggestion for @vast kelp:
discord Application Commands: Application Command Object
choices?
read more

wise hound
#

And you don’t need to change the type at all

vast kelp
#

I don't understand

#

which one is needed for me

#

oh oh

#

got it

glossy zinc
#

Do

#

choices: []

#
"choices": [
                {
                    "name": "Dog",
                    "value": "animal_dog"
                },
                {
                    "name": "Cat",
                    "value": "animal_cat"
                },
                {
                    "name": "Penguin",
                    "value": "animal_penguin"
                }
            ]```
#

Like this

vast kelp
#

got it thanks

glossy zinc
#

Wait

#

Send the code

#
options: [
        {
            name: "user",
            description: "The user you want to add the role to",
            required: true,
            type: "USER"
        },
        {
            name: "section",
            description: "The user you want to add the role to",
            required: true,
            type: "STRING"
            choices: [
                  {
                    name: "test"
                    value: "test"
                  }
                    ]
            
        }
    ],
#

Like this

vast kelp
# glossy zinc Send the code
module.exports = {
    name: "new-staff",
    description: "give role to new staff",
    user: ["ADMINISTRATOR"],
    options: [
        {
            name: "user",
            description: "The user you want to add the role to",
            required: true,
            type: "USER"
        },
        {
            name: "section",
            description: "The user you want to add the role to",
            required: true,
            type: "STRING",
            choices: [
                {
                    "name": "mta",
                    "value": "mta_roles"
                },
                {
                    "name": "fivem",
                    "value": "fivem_roles"
                }
            ]
        }
    ],
    /**
     *
     * @param {Client} client
     * @param {CommandInteraction} interaction
     * @param {String[]} args
     */
    run: async (client, interaction, args) => {
        const section = interaction.options.getString("section")
        const user = interaction.options.getMember('user');

        if (section === 'mta_roles') {
            const mta_roles = ['1000138410075377706', '1000138410268311563'];

            mta_roles.forEach(async role => {
                let rl = interaction.guild.roles.cache.find(r => r.id == role);
                user.roles.add(rl);
                await wait(500);
            })
            await interaction.reply({ content: ':ballot_box_with_check: Success (MTA)', ephemeral: true });
        } else if (section === 'fivem_roles') {
            const fivem_roles = ['1000138410230558804', '1000138410268311562'];

            fivem_roles.forEach(async role => {
                let rl = interaction.guild.roles.cache.find(r => r.id == role);
                user.roles.add(rl);
                await wait(500);
            })
            await interaction.reply({ content: ':ballot_box_with_check: Success (FIVEM)', ephemeral: true });
        }
    }
};
glossy zinc
#

Yes good

#

It should work now