How to fetch all online users in a guild, including idle and dnd
See title
Code:
guild.members.cache.filter(member => member.presence?.status === 'online' && !member.user.bot).size;
DiscordJs Ver: 14.7.1
Rest Ver: 10
Node Ver: 18.14.19 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
fetch them from the guild first
const members = await guild.members.fetch()
then filter that listProblem is my function is not async
then make it async
by the way why would you need to fetch all members every 1.5 seconds
just for the test
spamming the api "just for testing" is not justifiable tho
good point
Well doesnt work idk why
Had to change the loop to a for loop and made the execution async (commeted out the interval)
but the looks like the isnt coming to action cuz the console.log(members) isnt called
if you have a lot of guilds this is even worse than using an interval. Do you have the Guilds and the GuildMembers intent enabled in your bot?
the Guild Members intent has to also be enabled in your developers portal
Is enables in developer portal and intents are right, and its just my testbot on my test server so only one, but i need the loop for my main bot with 10+ servers
Found a solution doing it this way:
Thanks for your help