The Texan Doom Guy
The Texan Doom Guy
DIAdiscord.js - Imagine an app
Created by The Texan Doom Guy on 8/12/2024 in #djs-questions
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
}.`
);
}
});
6 replies