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

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

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 Relatório

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 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