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 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.
d.js docs
d.js docs2y 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
monbrey2y ago
Its also worth noting that if a user is offline, they dont have a presence You should be optional chaining that
kokastar
kokastarOP2y ago
Privileged intent should be enabled.
SpecialSauce
SpecialSauce2y ago
And in Client constructor?
kokastar
kokastarOP2y 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
monbrey2y ago
its this then
kokastar
kokastarOP2y ago
I'm able to resolve the issue.
Want results from more Discord servers?
Add your server