简体   繁体   中英

How do I find all members who don't have a role? discord.js v12

I'm trying to find all members who don't have a specific role. Here's the code I could think of:

message.guild.members.forEach(member => if (!member.roles.cache.has('role id') {
  console.log("Doesn't have the role.")
}));

Your JS sytnax is wrong, and you are interchanging .cache and no .cache

message.guild.members.cache.forEach(member => {
  if(!member.roles.cache.has(role_id) {
     console.log("Doesn't have the role");
  }
});

Also look at:

const invalid =  message.guild.members.cache
    .filter(member => member.roles.cache.has(role_has));

forEach takes a callback, if you want to use an if statement you will still need the brackets

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM