const ms = require('ms'); const { EmbedBuilder } = require('discord.js'); const { ApplicationCommandType, ApplicationCommandOptionType } = require('discord.js'); module.exports = { name: 'guide', description: 'A guide of everything you need to know!', voiceChannel: false, options: [ { name: 'guide', description: 'Select a guide to continue', type: ApplicationCommandOptionType.String, required: true, choices: [ { name: "data", value: "guide_data" }, { name: "codebean", value: "guide_code", description: "A guide on CodeBean" } ] } ], async execute({ inter }) { const DataGuide = new EmbedBuilder() .setColor('#5679EF') .setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) }) .setTitle('📰 Guide') .setDescription("How we use your data and how to prevent us from using your data") .setFooter({ text: 'Powered by Nonay', iconURL: inter.member.avatarURL({ dynamic: true })}); const CodeBean = new EmbedBuilder() .setColor('#5679EF') .setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) }) .setTitle('📰 Guide') .setDescription("code things") .setFooter({ text: 'Powered by Nonay', iconURL: inter.member.avatarURL({ dynamic: true })}); const adata = inter.options.getChoice('guide_data'); const acode = inter.options.getChoice('guide_code'); switch (adata) { case 'data': await inter.reply({ embeds: [DataGuide] }) } switch (acode) { case 'codebean': await inter.reply({ embeds: [CodeBean] }) } }, };
Basically, what I am trying to do is provide people with a guide of what to do with my bot but I cant figure out how to use choices and how to respond to a certain choice that gets selected (for example, someone selects ‘data’ and gets a guide about their data)
Advertisement
Answer
Most of what you have typed in is correct actually. There’s just two mistakes. When you declare choices for an option, you have to give it a name
property and a value
property. The name
property tells what the choice would look like on the app and the value
property is what you would receive if the user selected the option. You also seem to have misunderstood that choices are not another option by itself. It just gives a few hardcoded choices for the user to select from if the command had a string option. So, there isn’t anything called as getChoice()
So, your fixed code would look like this:
const ms = require('ms'); const { EmbedBuilder } = require('discord.js'); const { ApplicationCommandType, ApplicationCommandOptionType } = require('discord.js'); module.exports = { name: 'guide', description: 'A guide of everything you need to know!', voiceChannel: false, options: [ { name: 'guide', description: 'Select a guide to continue', type: ApplicationCommandOptionType.String, required: true, choices: [ { name: "data", value: "guide_data" }, { name: "codebean", value: "guide_code", description: "A guide on CodeBean" } ] } ], async execute({ inter }) { const DataGuide = new EmbedBuilder() .setColor('#5679EF') .setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) }) .setTitle('📰 Guide') .setDescription("How we use your data and how to prevent us from using your data") .setFooter({ text: 'Powered by Nonay', iconURL: inter.member.avatarURL({ dynamic: true })}); const CodeBean = new EmbedBuilder() .setColor('#5679EF') .setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) }) .setTitle('📰 Guide') .setDescription("code things") .setFooter({ text: 'Powered by Nonay', iconURL: inter.member.avatarURL({ dynamic: true })}); const guide = inter.options.getString('guide'); // This gets whatever the user typed in for the guide option switch (guide) { case "guide_data": await inter.reply({ embeds: [DataGuide] }) break; case "guide_code": await inter.reply({ embeds: [CodeBean] }) break; } }, };