How do i get member count of a specific guild

const { Events } = require('discord.js');

module.exports = {
name: Events.ClientReady,
once: true,
async execute(client) {
const guild = await client.guilds.fetch('1163579453742514266');
const members = await guild.members.fetch();
console.log(members);
console.log(members.guild);
console.log(members.memberCount);
client.user.setPresence({ activities: [{ name: 'Watching over members' }], status: 'online' });
},
};
const { Events } = require('discord.js');

module.exports = {
name: Events.ClientReady,
once: true,
async execute(client) {
const guild = await client.guilds.fetch('1163579453742514266');
const members = await guild.members.fetch();
console.log(members);
console.log(members.guild);
console.log(members.memberCount);
client.user.setPresence({ activities: [{ name: 'Watching over members' }], status: 'online' });
},
};
I want to get all the members in my specific guild but when i try to use members.memberCount it says undefined (check screenshots below) and i though maybe you guys could help
No description
No description
3 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
d.js docs
d.js docs14mo ago
Getting your bot's member count - client.users.cache.size is unreliable because it will only return cached users - The preferred method is using collection.reduce() on client.guilds.cache
client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0)
client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0)
rallemakralle
rallemakralleOP14mo ago
My bad, sorry for posting in here😁
Want results from more Discord servers?
Add your server