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

164
Views
How to count all online members using v13?

So I'm currently trying to get all online members in a specific guild and count them. I already tried these methods:

let onlineMembers = (await interaction.guild.members.fetch()).filter(
      (member) => !member.user.bot && member.user.presence.status !== "offline"
    );

and

let onlineMembers = interaction.guild.members.cache.filter(member => member.presence.status !== "offline").size

I also tried fetching all members first and filter the result like this:

const allMembers = await interaction.guild.members.fetch();
const onlineMembers = allMembers.filter(member => !member.user.bot && member.presence.status !== "offline");

But I'm always getting this exception:

TypeError: Cannot read property 'status' of undefined

So I went looking for a solution and I noticed that I manually have to activate all intents I want my bot to use. I "activated" the needed intents in my index.js like this:

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

But this didn't fix my problem either.

In the Discord Developer Portal I also enabled both privileged gateway intents:

Privileged Gateway Intents activated

And who could have guessed...it still doesn't work. It's weird, because for some members it's working but I need it to work for every member.

Does somebody know how to fix this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Fetching this information changed in V13

This code will generate an Object with the properties online, idle and dnd:

let GUILD_MEMBERS = await client.guilds.cache.get(config.ids.serverID).members.fetch({ withPresences: true })

var onlineMembers = {
 online: await GUILD_MEMBERS.filter((online) => online.presence?.status === "online").size,
 idle: await GUILD_MEMBERS.filter((online) => online.presence?.status === "idle").size,
 dnd: await GUILD_MEMBERS.filter((online) => online.presence?.status === "dnd").size
}

Let me know, if this works for you

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!