简体   繁体   中英

how to store all the data of only the members who have a specific role with discordjs v12

I have a discord js related problem....I actually want to get all the members in the guild with one specific role yeet1 in a single array.

This is what I have tried so far:

if(msg.content.toLowerCase().startsWith('+info mod')){
    const Members = msg.guild.members.cache.filter(mem => mem.roles.cache.find(role => role.id == '822075908231659550')).map(member => member.user.tag).join('\n');
    console.log(Members);
    msg.channel.send(`Users with yeet1: ${Members}`);
}

But it returns an empty array.

This question is already answered here How do I list all Members with a Role In Discord.Js

If you still need help try this

let membersWithRole = message.guild.members.filter(member => { 
        return member.roles.cache.find("name", roleName);
    }).map(member => {
        // Do whatever you want
    })

Here's a way more easy way (Might need intents)

message.guild.roles.get('415665311828803584').members.map(m=>m.user.tag)

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