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

138
Vistas
Get the number of members of a discord server

For a project, I need to export the total number of members of a Discord server list. Is there a way to get this number without accessing the server? So far I've tried something with what I've found on various forums but I get an error: Cannot read properties of undefined (reading 'memberCount')


const { Client, Intents } = require('discord.js');

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

const token = 'MyToken';

client.login(token);

client.on('ready', async () => {
    let myGuild = await client.guilds.cache.get('798982176502054933');
    let memberCount = myGuild.memberCount;
    console.log(memberCount);
});
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

client.guilds.cache.get('798982176502054933') doesn't return a promise as it is a collection so you don't have to use await with it.

let myGuild = client.guilds.cache.get('798982176502054933');
let memberCount = myGuild.memberCount;
console.log(memberCount);
about 4 years ago · Juan Pablo Isaza Denunciar

0

a better approach for this is to use the .fetch(id) function. this code waits for the fetch to find the guild then will console log the guild member count. if your bot cant find the server it will throw an error.

client.on('ready', async () => {
    await client.guilds.fetch('798982176502054933')
    .then(myGuild => {
      console.log(myGuild.memberCount)
    })
});
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