I am trying to check the reactions of a specific message by storing its message id. I'm using discord.js.
The problem
The problem is that when using my code, I get this error: TypeError: Cannot read property 'id' of undefined. Maybe it's because it's an embed? What I am trying to do is getting the id of the sent embed and writing it into a file. Then, in the code that handles the reactions, I should get the id wrote on the file, and test if that is the correct message the reaction has been added to.
My code
async function tembed(message) {
const mention = message.mentions.members.first();
if (mention.roles.cache.find(r => r.name === "dittatore")) {
message.channel.send(`Cannot eject **${mention}**.`);
message.channel.bulkDelete(1);
}
if (mention.roles.cache.find(r => r.name === "dittatore")) return;
message.channel.bulkDelete(1);
const testembed = {
color: '#7A2F8F',
title: 'test',
description: `${mention} this is a test embed`,
footer: 'test footer',
};
let sent = await message.channel.send({ embed: testembed }).then(async (embedMessage) => {
await embedMessage.react('✅');
await embedMessage.react('❌');
});
let id = sent.id; //TypeError: Cannot read property 'id' of undefined
fs.writeFile('/home/pi/botstuff/testembed.txt', id, (err) => {
if (err) throw err;
});
console.log(`wrote ${id} on file`);
const channel = message.guild.channels.cache.get("770735002182877224");
channel.send(`${mention}`);
}