Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
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 = '${interaction.guild.id}'`
                const editmenu = new MessageSelectMenu()
                    .setCustomId('editselect')
                    .setPlaceholder('🔧 Select tickettype to edit')
                    .addOptions([
                        {
                            label: 'None',
                            description: 'Empty',
                            value: 'none',
                        },])
                await sql.query(query, function(err, result) {
                    if(err) throw err;
                    console.log(result)
                    result.forEach(item => {
                        editmenu.addOptions([
                            {
                                label: '' + item.name,
                                description: '' + item.name,
                                emoji: '' + item.emoji,
                                value: '' + item.id,
                            },
                        ]);
                    });
                });

                editmenu.addOptions([
                    {
                        label: '2 Test',
                        description: 'Empty',
                        value: 'test',
                    },
                ])
                editrow.addComponents(editmenu);
                const editembed = new MessageEmbed()
                    .setColor('YELLOW')
                    .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})
            }
            break;

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

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda