@jerad
To list all members with a specific role using discord.js, you can follow these steps:
1 2 3 |
const role = message.guild.roles.cache.find(role => role.name === 'ROLE_NAME'); // or const role = message.guild.roles.cache.get('ROLE_ID'); |
1 2 3 4 5 6 |
const membersWithRole = message.guild.members.cache.filter(member => member.roles.cache.has(role.id)); membersWithRole.forEach(member => { console.log(member.user.tag); // You can store the member data or perform any other actions here }); |
Make sure to replace 'ROLE_NAME' or 'ROLE_ID' with the actual name or ID of the role you want to list members for. This code snippet assumes you are using Discord.js v12.