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

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)
)
)
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
No description
10 Replies
d.js toolkit
d.js toolkit2w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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!
NyR
NyR2w ago
Use autocomple option
d.js docs
d.js docs2w ago
:guide: Slash Commands: Autocomplete read more
mallusrgreat
mallusrgreat2w ago
why would they use autocomplete? the servers are already available to them, they don't need to get them from the outside
NyR
NyR2w ago
And...? To show choices dynamically, you'll have to use autocomplete, regardless of where the data comes from
mallusrgreat
mallusrgreat2w ago
wdym dynamically though? i don't think he wants to do anything "dynamic" here
NyR
NyR2w ago
Read the title...
mallusrgreat
mallusrgreat2w ago
oh i completely missed that, sorry
zen1th
zen1th6d ago
Well if SQL data sql dont change so much, it will be better to use choices
Fammy player
Fammy playerOP6d ago
but the choices are not getting registered with the command
Want results from more Discord servers?
Add your server