0

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?

Adventune
  • 1,241
  • 1
  • 8
  • 13
  • I think it has something to do with intents. See if [this](https://stackoverflow.com/questions/64739350/discord-js-bot-welcomes-member-assign-a-role-and-send-them-a-dm/64739684#64739684) helps you. – Worthy Alpaca Apr 08 '21 at 19:05
  • @WorthyAlpaca That solved it! Thank you! – Adventune Apr 08 '21 at 19:20

1 Answers1

0

Problem was with intents! Here is link to a SOF question with similar problem and how to solve it!

Discord.js Bot Welcomes Member, Assign a Role and send them a DM

Adventune
  • 1,241
  • 1
  • 8
  • 13