I'm developing a discord bot and faced a small problem, I use "messageReactionRemove" and "messageReactionAdd" to remove or add certain roles, the problem happens when the user leaves the server, as when he leaves, certain user reactions are removed using "guildMemberRemove", which again calls "messageReactionRemove", but the user is no longer on the server (error).
client.on('messageReactionRemove', (reaction, user) => {
if (reaction.message.id == '1110918756189884496') {
let role = reaction.message.guild.roles.cache.find(role => role.name === "Verified");
reaction.message.guild.members.cache.get(user.id).roles.remove(role);
}
});
client.on("guildMemberRemove", (member) => {
const channel = member.guild.channels.cache.find((ch) => ch.id === '1109131318350053457');
channel.messages.fetch(`1110918756189884496`).then(message => {
message.reactions.cache.find(reaction => reaction.emoji.name == "✅").users.remove(member.user.id);
})
});
If I use fetch() instead of cache, then I get an error (Unknown member)
Do you have any ideas? Thanks for any information