Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

307
Vistas
Discord.js update cache to pull all members that have role

Currently having issues pulling all members that have a certain role. I can currently pull a list of names but only those that are cached currently. If i leave my bot running for a few hrs it will pull more but it never pulls all members that have that role. Ive read a few different things about using the .fetch() command but still no dice.

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


msg.channel.send('exporting all members with delcared role');

msg.guild.roles.fetch('guildId');//cache roles i think?
let role = msg.guild.roles.cache.find(r => r.name === 'Sysadmins');


msg.guild.members.fetch('roleId');//cache members i think?
let list = msg.guild.roles.cache.get(roleID).members.map(m => m.nickname)

console.log(role);
console.log(list);

The console.log(); returns my nickname as expected but only mine and i know there are at least 10 others with this role.

Other questions similar that I have already tried:

Similar Question #1

Similar Question #2

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

@DanLop your answer along with @MrMythical and a few other stack overflow questions helped me get this one sovled. I was able to use the async functions properly to pull all the data i need below is what i ended up with.

Solution:

client.on('messageCreate', async msg => {  //TODO here });

let list = client.guilds.cache.get(tempGuildId);

try {
    await list.members.fetch();

    let role1 = list.roles.cache.get(roleId).members.map(m => m.displayName);
    console.log(role1);
} catch (err) {
    console.error(err);
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

It's close, but much simpler, with 3 lines

await msg.guild.members.fetch() // fetch all members and cache them
const role = msg.guild.roles.cache.get("id") // get role from cache by ID (roles are always cached)
const list = role.members.map(m => m.nickname) // map members by nickname
about 4 years ago · Juan Pablo Isaza Denunciar

0

Since you're giving the fetch() method a String argument, only the user matched with that String will be fetched, more like a get(). Also, the fetch() method returns a Promise, which means the method must be awaited to actually recieve the data.

Your fetch() method should look like this:

await msg.guild.members.fetch();

This way you tell Node.js it must wait until you recieve the data promised before continue.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda