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

137
Views
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 answers
Answer question

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 Report

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