Detecting role removal

client.on('guildMemberUpdate', (oldMember, newMember) => {
const roleID = '899870393282752542';

const removedRoles = oldMember.roles.cache.filter(role => !newMember.roles.cache.has(role.id));

if (removedRoles.has(roleID)) {
console.log(`Role with ID ${roleID} was removed from ${oldMember.user.username}`);
}
});
client.on('guildMemberUpdate', (oldMember, newMember) => {
const roleID = '899870393282752542';

const removedRoles = oldMember.roles.cache.filter(role => !newMember.roles.cache.has(role.id));

if (removedRoles.has(roleID)) {
console.log(`Role with ID ${roleID} was removed from ${oldMember.user.username}`);
}
});
When role is removed, it should be logged in the console. However, it only works if the role i remove the role of myself, not if i remove it from someone else.
5 Replies
d.js toolkit
d.js toolkit13mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Squid
Squid13mo ago
You may need partials since the event may not emit on uncached members It worked on you because you were cached at the time, but it's not working on others since they were uncached
scotty
scotty13mo ago
Ahh, makes sense. Thank you!
Danial
Danial13mo ago
It would be the GuildMember partial, right?
Squid
Squid13mo ago
I would assume so