Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda