Skip to content Skip to sidebar Skip to footer

Get All Users With Role

I'm trying to get all users that have an role using discord.js. let roleFromID = message.guild.roles.cache.get(roleID) I need an array with every user with that role. This is what

Solution 1:

You just need to use Role.members. This returns a collection of members with the role.

const role = await message.guild.roles.fetch('role-id');
await message.guild.members.fetch();
const { members } = role //Collection of members

Solution 2:

This should work:

msg.guild.members.cache.filter(member=>member.roles.cache.find(role=>role.id==roleID))//.forEach(m=>{console.log(m.user.username)})

Post a Comment for "Get All Users With Role"