So i am trying to get all of the server members with certain role with the following code
// REMOVE FROM ALL -----------------------------------------------
if(args[0] == 'removeFromAll'){
var role = msg.mentions.roles.first();
if(role == null) {
Embeds.removeFromAllNoRole(msg)
break;
}
let roleID = role.id;
const membersWithRole = msg.guild.members.cache.filter((member) => member.roles.cache.some((role) => role.id === roleID)).map(m => m)
membersWithRole.forEach(member => {
member.roles.remove(roleID)
.then(function() {
console.log(`Removed role from user ${member.user.tag}!`);
})
})
Embeds.removeFromAllFinished(msg)
}
And then remove their roles. This however only removes the role from the bot its self and the user sending the command.
I have tried at least all of these solutions:
Code returns all members and not the members in the role
https://www.codegrepper.com/code-examples/javascript/discord.js+v12.2.0+get+all+members+of+a+role
How to remove a role from every member of the guild
How do I list all Members with a Role In Discord.Js
And none of them haven't worked for me!
What is going wrong and how do I fix it?