How do I find how many guilds my bot is in?

Scott Elsy picture Scott Elsy · Jul 28, 2018 · Viewed 11.9k times · Source

I have a discord bot, and I was just wondering: how do I find out how many guilds the bot is in? So that if I say -guilds it'll tell me how many guilds it's in.

Answer

Trifex picture Trifex · Jul 28, 2018

I'll leave the command up to you, but to get the bot's available guilds, you must use <Client>.guilds.

This is a collection of guilds so to get the size of a collection all you have to do is <Client>.guilds.size

This information is also on the discord.js docs.

I hope this helps!

- Trifex

Update

In the comments, @NicoHd105 noted that as of discord.js v12, the proper way to retrieve a collection of all guilds a bot is part of is <Client>.guilds.cache, meaning to get the size of the guilds you must use <Client>.guilds.cache.size!