#[solved] Get member count while filtering out bots
17 messages · Page 1 of 1 (latest)
• 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.
ok so I have to pull from the cache to get a list of members to filter through. oh ok. gotcha. thank you
this is only showing 1 when it should show 3.
👆
ok so how do I fetch them before?
<Guild>.members.fetch() and wait for the promise to resolve
const guildMembers = interaction.guild.members.fetch();
const memberCount = guildMembers.filter(member => !member.user.bot).size;
```I guess I'm lost. I did that, but it's telling me it's not a function...
yep...lost
Resources to understand Promise:
• MDN: learn more
• Guide: learn more
• JavaScript info: learn more
const promise = new Promise(resolve => resolve(interaction.guild.members.fetch()))
const guildMembers = await promise;
const memberCount = guildMembers.filter(member => !member.user.bot).size;
```this was modeled from https://bobbyhadz.com/blog/javascript-wait-promise-resolve-before-returning#:~:text=async%20function%20getNum()%20%7B%0A%20%20const%20promise%20%3D%20new%20Promise(resolve%20%3D%3E%20resolve(42))%3B%0A%0A%20%20const%20num%20%3D%20await%20promise%3B%0A%0A%20%20console.log(num)%3B%20//%20%F0%9F%91%89%EF%B8%8F%2042%0A%0A%20%20return%20num%3B%0A%7D%0A%0AgetNum()%0A%20%20.then(num%20%3D%3E%20%7B%0A%20%20%20%20console.log(num)%3B%20//%20%F0%9F%91%89%EF%B8%8F%2042%0A%20%20%7D)%0A%20%20.catch(err%20%3D%3E%20%7B%0A%20%20%20%20console.log(err)%3B%0A%20%20%7D)%3B
Don’t search for code involving those two words. Actually learn how they work/what they are. Else you‘ll be lost within djs, as 80% of its methods are promise based
ok. I've pinned the tab for the js info link you gave. I'll read over it after work. thank you