How to add choice to slash command?

Hey, I want to add choices to the option named "section", But I don't know how. Can you guide me?
const { Client, CommandInteraction , MessageEmbed } = require("discord.js");

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 });
}
}
};
const { Client, CommandInteraction , MessageEmbed } = require("discord.js");

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 });
}
}
};
13 Replies
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Pooyan
Pooyan17mo ago
node js v 16 discord.js v13.12.0
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Pooyan
Pooyan17mo ago
I want to add choices to the "section" option
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Pooyan
Pooyan17mo ago
tnx
d.js docs
d.js docs17mo ago
Suggestion for @pooyaneftekhari:discord Application Commands: Application Command Object choices? read more
Pooyan
Pooyan17mo ago
uh I don't understand which one is needed for me oh oh got it
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Pooyan
Pooyan17mo ago
mhm got it thanks
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Pooyan
Pooyan17mo ago
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 });
}
}
};
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 });
}
}
};
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View