GuildMemberRoleManager.remove() removes more than one role

I'm calling GuildMemberRoleManager.remove() in my code, supplying it with an Array containing a single role. However, this also removes another role I haven't specified. Things I've already checked: 1. I started logging the array right before calling the method. Array still only contains the single role. 2. Logging also showed that I'm not calling the method (or parent function) twice. 3. The only other method that could remove roles .set() does not get called. 4. This doesn't seem to be caused by run time conditions stemming from forgotten await statements. Relevant code:
// Only remove one set of roles
console.log(rolesToRemove)
await member.roles.remove(rolesToRemove)
.catch(error => {
console.error(`Error removing roles for member ${member.displayName}. Is the bot maybe missing the "manage roles" permission?`)
console.error(error)
})
// Only remove one set of roles
console.log(rolesToRemove)
await member.roles.remove(rolesToRemove)
.catch(error => {
console.error(`Error removing roles for member ${member.displayName}. Is the bot maybe missing the "manage roles" permission?`)
console.error(error)
})
Repo: https://github.com/NKN1396/Discord-EmojiToRole/blob/f2500c0254841118c628c342d45780b3e42aa15c/src/trackReactions.mjs#L161 Help would be greatly appreciated, as I've been grinding my teeth out for the past 2 hours.
5 Replies
NKN1396
NKN13962y ago
(forgot image for "after")
monbrey
monbrey2y ago
Do you have the GuildMembers intent enabled?
NKN1396
NKN13962y ago
No, as I don't want to use privileged intents
monbrey
monbrey2y ago
Well thats the issue here. The internal role cache for discord.js likely doesn't know that the other role has been added. When you provide an array, it internally calculates the difference and calls .set iirc But its doing that with an invalid cache So it's setting it to a list that is missing both
NKN1396
NKN13962y ago
I actually just wanted to upload a video of it, but I think your response is already hinting me into the correct direction. Thank you very much for the insight, I'll try caching the roles before calling .remove