I am attempting to make a simple starboard system on discord.js, and the deleting a message part is stumping me. Currently, if a message gets a star, an embed is created in a starboard channel, and, critically, the footer is the original message's id. I want to make the inverse function (when the star is removed, the embed is deleted) work by finding the embed with that footer and then deleting that embed, but it's not working for some reason. The error I keep getting is "UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'cache' of undefined." How do I property define this variable?
if (reaction.emoji.name === `⭐`) {
const guild = reaction.message.guild;
await reaction.fetch();
const stars = reaction.count;
if (stars === 0) {
const embed = guild.messageEmbed.cache.find(embed => embed.footer === reaction.message.id);
embed.delete
}
}
}