Skip to content

How to use a SQL Result in Discord.JS SelectMenus?

I am trying to add Options to a SelectMenu from a SQL request. My code is the following:

case "edit":{
                const editrow = new MessageActionRow();
                let query = `SELECT * FROM tickettypes WHERE guild_id = '${}'`
                const editmenu = new MessageSelectMenu()
                    .setPlaceholder('🔧 Select tickettype to edit')
                            label: 'None',
                            description: 'Empty',
                            value: 'none',
                await sql.query(query, function(err, result) {
                    if(err) throw err;
                    result.forEach(item => {
                                label: '' +,
                                description: '' +,
                                emoji: '' + item.emoji,
                                value: '' +,

                        label: '2 Test',
                        description: 'Empty',
                        value: 'test',
                const editembed = new MessageEmbed()
                    .setTitle('Edit tickettype')
                    .setAuthor({ name: interaction.user.username})
                    .setDescription('Select the tickettype you want to edit')
                await interaction.reply({ embeds: [editembed], components: [editrow], ephemeral: true})

My Console is giving me the following output:

[SQL] Connected to the MySQL server! Connection ID: 95
[DISCORD] Succesfully established connection to Discord!
  RowDataPacket {
    id: 1,
    name: 'Test',
    emoji: '<:thumbsup:>',
    guild_id: 933323734322913300,
    prefix: 'test',
    openheader: 'Test Ticket',
    openmsg: 'Welcome, this is a test.'

There are no Errors. Still Discord doesn’t add it. It looks like this:

Discord View of the Select Menu

I have no clue, what i did wrong. Please help me out. Thanks in advance



When you fetch the data from sql, your code doesn’t wait for it. It instead continues on, and the callback function you provided in the query will only be executed once the query was completed. This is why you have the option of 2 Test but you don’t have the result options. One way to fix it would be to move all the code after the result into the callback function, then they would only be executed once the query was completed

User contributions licensed under: CC BY-SA
1 People found this is helpful