Cannot get online users

I am trying to get an online user on that server when I use the s slash command. At that time, an error occurred. I have tried various devices but could not get it to work. Code
const members = await interaction.guild.members.fetch({ withPresences: true });
const online = members.filter(member => member.presence.status !== "offline").size;
const members = await interaction.guild.members.fetch({ withPresences: true });
const online = members.filter(member => member.presence.status !== "offline").size;
Error
TypeError: Cannot read properties of null (reading 'status')
TypeError: Cannot read properties of null (reading 'status')
8 Replies
d.js toolkit
d.js toolkit15mo 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.
d.js docs
d.js docs15mo ago
Error [DisallowedIntents]: Privileged intent provided is not enabled or whitelisted. If you are using the GuildMembers, GuildPresences, or MessageContent intents, you need to enable them in the developer portal: • Developer Portal > Your app > Bot > Privileged Gateway Intents
monbrey
monbrey15mo ago
Its also worth noting that if a user is offline, they dont have a presence You should be optional chaining that
kokastar
kokastar15mo ago
Privileged intent should be enabled.
SpecialSauce
SpecialSauce15mo ago
And in Client constructor?
kokastar
kokastar15mo ago
It should probably be enabled.
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences
],
partials: [Partials.Channel],
});
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences
],
partials: [Partials.Channel],
});
monbrey
monbrey15mo ago
its this then
kokastar
kokastar15mo ago
I'm able to resolve the issue.