Get All the Online Members of Discord using Discordie
Recently I had the requirement to get all the Online Members of a Discord Server. It was not as difficult as it seems to be. I will share that in this tutorial how to get that Step by Step.
In my previous tutorial post Send Message to Discord using Discordie NPM Package, I have told why I use Discordie. To get started with Discordie all the information are there on that post like Installation and the basics.
Now when you are up and running with the Discordie you will get all the Users using the command console.log(client.Users);
, but the drawback of using it is that it will give it as a IUserCollection.
Now when we have all the IUserCollection to get the Users from it we can create a loop(forEach) to go through all the members in the loop like below:
client.Users.forEach(user => { });
When you try to get the contents of each user by writing console.log(user)
you will get it as an IUser as shown below which has id, username, discriminator, avatar and bot which are discord properties.
But along with this we have one more property known as status which will give me the status of that particular IUser as shown below :
client.Users.forEach(user => {
console.log(user);
console.log(user.status);
});
So you can filter out the Online Members with Offline Members, but there are methods to do it also if you know the channel id and guild id.
Posted on Utopian.io - Rewarding Open Source Contributors