Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
How to list all members with a specific role with discord.js?

I try to make a simple bot that just lists all members that have a specific role.

I went through most of the similar questions I could find, but their answers seem outdated. So I tried this but end up with the result 'undefined', although the role exists.

const discord = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new discord.Client(
    { intents: [
        Intents.FLAGS.GUILDS, 
        Intents.FLAGS.GUILD_MESSAGES,
        Intents.FLAGS.GUILD_MEMBERS
    ] });


const prefix ="!";
const MemberID = "912852591023628371";

client.on('ready', () => {
    console.log('Connected to the bot');

  

});

client.on('messageCreate', msg => {
    if (msg.content === 'hi') {
        msg.reply('Hi to you too!');
    }
  
});

client.on('messageCreate', async message => {
    if (message.content === prefix + 'list') {
        let list = client.guilds.cache.get(MemberID);
        console.log(list);
        }
    }
);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just use this:

    message.guild.roles.cache.get('Your role id here').members.map(m=>m.user.tag);

This will return an array of all users with the role.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!