'Grabbing specific reaction from embed (discord.js)

So I am working on a Discord bot using discord.js and I am stumped with how I would get the reaction from a specific embed. My current reaction function looks for any check mark react and approves the next row in the database. I need it so that the row that corresponds to the embed is updated since the row will be altered whenever a check mark is added as a reaction to any message.

I have tried adding a number variable to the embed and using that as the result number however it did not work. I am very new to this (which is also why it may not be the best code you have ever seen) so I apologise in advance for anything that I may have missed/got wrong.

const timer = ms => new Promise(res => setTimeout(res, ms))

async function load () { // We need to wrap the loop into an async function for this to work
  for (var i = 0; i => 0; i++) {
    var sql = "SELECT * FROM shouts WHERE status = 'awaiting notification' LIMIT 1";
    connection.query(sql, function (err, result) {
        if (result.length > 0) {
            var updatesql = "UPDATE shouts SET status = 'awaiting verification' WHERE ID = " + result[0].id
            connection.query(updatesql, function (upderror, updresult) {
                const uploadembed = new djs.MessageEmbed()
                    .setColor('#010101')
                    .setTitle('New Upload')
                    .setImage(result[0].file_link)
                    .addFields(
                        { name: 'Name', value: result[0].file_name, inline: true },
                        { name: 'Link', value: result[0].file_link, inline: true }
                    )
                    .setFooter({ text: 'Uploaded pending' })
                    .setTimestamp()
                client.channels.fetch('855605483401773066').then(channel => channel.send({ embeds: [uploadembed] }).then(react => {
                    react.react("✅");
                    react.react("❌");
                }));
            })
        }
    })
    await timer(5000); // then the created Promise can be awaited
    }
}

load();

client.on('messageReactionAdd', (reaction, user) => {
    var sql = "SELECT id, file_name, uploaded_on, file_link FROM shouts WHERE status = 'awaiting verification'";
    connection.query(sql, function (err, result) {
        if (reaction.emoji.name == '✅' && !user.bot) {
            var updatesql = "UPDATE shouts SET status = 'confirmed' WHERE ID = " + result[0].id
                connection.query(updatesql, function (upderror, updresult) {
                const uploadembed = new djs.MessageEmbed()
                    .setColor('#44dd44')
                    .setTitle('Upload Approved')
                    .setImage(result[0].file_link)
                    .addFields(
                        { name: 'Name', value: result[0].file_name, inline: true },
                        { name: 'Link', value: result[0].file_link, inline: true }
                    )
                    .setFooter({ text: 'Approved by ' + user.username })
                    .setTimestamp()
                reaction.message.edit({ embeds: [uploadembed] }).then(react => {
                    react.reactions.removeAll();
                })
            })
        } 
    })
})```

Any help at all is greatly appreciated.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source