Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda