GuildMemberUpdate only fires when my bot's roles are modified.

The code I'm using works, but it only works on my bot. It doesn't seem to detect when another member has their roles changed. I'm using the example used on the faq page on https://discordjs.guide/popular-topics/faq.html.
client.on(Events.GuildMemberUpdate, (oldMember, newMember) => {
// If the role(s) are present on the old member object but no longer on the new one (i.e role(s) were removed)
const removedRoles = oldMember.roles.cache.filter(
(role) => !newMember.roles.cache.has(role.id)
);
if (removedRoles.size > 0) {
console.log(
`The roles ${removedRoles.map((r) => r.name)} were removed from ${
oldMember.displayName
}.`
);
}
// If the role(s) are present on the new member object but are not on the old one (i.e role(s) were added)
const addedRoles = newMember.roles.cache.filter(
(role) => !oldMember.roles.cache.has(role.id)
);
if (addedRoles.size > 0) {
console.log(
`The roles ${addedRoles.map((r) => r.name)} were added to ${
oldMember.displayName
}.`
);
}
});
client.on(Events.GuildMemberUpdate, (oldMember, newMember) => {
// If the role(s) are present on the old member object but no longer on the new one (i.e role(s) were removed)
const removedRoles = oldMember.roles.cache.filter(
(role) => !newMember.roles.cache.has(role.id)
);
if (removedRoles.size > 0) {
console.log(
`The roles ${removedRoles.map((r) => r.name)} were removed from ${
oldMember.displayName
}.`
);
}
// If the role(s) are present on the new member object but are not on the old one (i.e role(s) were added)
const addedRoles = newMember.roles.cache.filter(
(role) => !oldMember.roles.cache.has(role.id)
);
if (addedRoles.size > 0) {
console.log(
`The roles ${addedRoles.map((r) => r.name)} were added to ${
oldMember.displayName
}.`
);
}
});
2 Replies
d.js toolkit
d.js toolkit5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
The Texan Doom Guy
The Texan Doom GuyOP5mo ago
oh crap i gotta update node nope still doesn't work on v22.6.0 Oh, thanks!
Want results from more Discord servers?
Add your server