- A bot with
MANAGE_WEBHOOKS
permissions on the guild.
This code fetches the guild manually in order to get all of its values, including the approximateMemberCount
(which is the
semi-up-to-date value indicating how many members are on your guild) and the approximatePresenceCount
which is the
semi-up-to-date value indicating how many ONLINE members are on your guild. Now, they aren't always precise to the member, but they're
close enough and are updated regularly. They're usually just a bit behind (a day or two, maybe?) in terms of data.
Once the guild is fetched, you now have the "Total" and "Online" members, but what about bots? For this we use the Integrations
endpoint. Integrations counts webhooks and such, so it needs the MANAGE_WEBHOOKS
permission - make sure yourt bot has it!
Guild Integrations are limited to 50, so you will never see a bot count higher than 50 using this method. Still, guilds with more than 50 bots are fairly rare, and this is better than nothing ^_^
As the code shows, you can easily create a single function that takes in a guild and returns the appropriate values. This function must be promise-based as it need to wait for guild.fetch() and fetchIntegrations() to work. Make sure to await the response!
This gist currently only has a method to use with discord.js 12.4.x. If you know how to do this with other libraries, in any language, please don't hesitate to let me know either by commenting below, and I'll add it to the list!