TypeError: Cannot read properties of undefined (reading 'status')

Why this code stopped working?
const guild = client.guilds.cache.get("944616601678917632");
const onlineCount = guild.members.cache.filter(m => m.user.presence.status === 'online').size;
console.log(onlineCount)
const guild = client.guilds.cache.get("944616601678917632");
const onlineCount = guild.members.cache.filter(m => m.user.presence.status === 'online').size;
console.log(onlineCount)
11 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Danial
Danial2y ago
Users don't have presence, members do, no need to put m.user just do m.presence.status
Pooyan
PooyanOP2y ago
Made no difference
Danial
Danial2y ago
Do you have GuildPresences intent?
Pooyan
PooyanOP2y ago
Yes I do
Danial
Danial2y ago
Shows the same error?
Pooyan
PooyanOP2y ago
Yes
const client = new Discord.Client(
{ intents: 32767 },
{ partials: ["MESSAGE", "CHANNEL", "REACTION", "GUILD_MEMBER"] }
);
const client = new Discord.Client(
{ intents: 32767 },
{ partials: ["MESSAGE", "CHANNEL", "REACTION", "GUILD_MEMBER"] }
);
This is my client
d.js docs
d.js docs2y ago
We highly recommend only specifying the intents you actually need. • Note, that 98303, 32767 or whatever other magic number you read that represents "all intents", gets outdated as soon as new intents are introduced. • The number will always represent the same set of intents, and will not include new ones. There is no magic "all intents" bit.
Pooyan
PooyanOP2y ago
Here, I changed it and it didn't make any change at all
const Discord = require("discord.js");
const client = new Discord.Client(
{ intents: 3276799 },
{ partials: ["MESSAGE", "CHANNEL", "REACTION", "GUILD_MEMBER"] }
);
const Discord = require("discord.js");
const client = new Discord.Client(
{ intents: 3276799 },
{ partials: ["MESSAGE", "CHANNEL", "REACTION", "GUILD_MEMBER"] }
);
Are you there? @Danial None of these fixed it:
const Discord = require("discord.js");
const client = new Discord.Client({
intents: 3276799,
partials: ["MESSAGE", "CHANNEL", "REACTION", "GUILD_MEMBER", "USER", "GUILD_SCHEDULED_EVENT"]
});
const Discord = require("discord.js");
const client = new Discord.Client({
intents: 3276799,
partials: ["MESSAGE", "CHANNEL", "REACTION", "GUILD_MEMBER", "USER", "GUILD_SCHEDULED_EVENT"]
});
d.js docs
d.js docs2y ago
guide Popular Topics: Gateway Intents read more
Pooyan
PooyanOP2y ago
Nevermind It was giving error because some members' presence was null. I fixed it with checking if the presence is not null:
const guild = client.guilds.cache.get("944616601678917632");
const onlineCount = guild.members.cache.filter(m => m.presence && m.presence.status === 'online').size;
const guild = client.guilds.cache.get("944616601678917632");
const onlineCount = guild.members.cache.filter(m => m.presence && m.presence.status === 'online').size;
Want results from more Discord servers?
Add your server