#how to add dynamically data from sql to .addchoice()

10 messages · Page 1 of 1 (latest)

native locust
#
let serverNames = client.serverNames;
console.log(serverNames) /* 
[
  { name: 'CCS', value: '228b5e70-d891-4179-a0db-6fcfc66ff054' },
  {
    name: 'Discord Bot',
    value: '13c0f5aa-e702-4388-baee-0e29e45c046c'
  },
  { name: 'dev', value: 'eaeb5525-ee49-4873-8fe2-16d68edd35a3' }
]*/
module.exports = {
    data: new SlashCommandBuilder()
    .setName("server")
    .setDescription("Server name")
    .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
    // sub command for power action on servers
    .addSubcommand(subcommand => subcommand
        .setName('power')
        .setDescription('Action you want to perform on server')
        .addStringOption(option => option
            .setName('servername')
            .setDescription("Server name which you want to start")
            .setRequired(true)
            .addChoices(...serverNames)
        )
        .addStringOption(option => option
            .setName('action')
            .setDescription('Action you want to perform')
            .addChoices(
                {name: 'Start', value: 'start'},
                {name: 'Restart', value: 'restart'},
                {name: 'Stop', value: 'stop'},
                {name: 'Kill', value: 'kill'}
            )
            .setRequired(true)
        )
    )

When i register this command the options are not shown

paper eagleBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
lyric glen
#

Use autocomple option

pure cloakBOT
lost leaf
lyric glen
#

And...? To show choices dynamically, you'll have to use autocomplete, regardless of where the data comes from

lost leaf
lyric glen
#

Read the title...

lost leaf
#

oh i completely missed that, sorry

somber cape
#

Well if SQL data sql dont change so much, it will be better to use choices