3
votes

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.

3

3 Answers

6
votes

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!

1
votes

A .Net sample as well

var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bot " + token);

HttpResponseMessage guildsResponse = await client2.GetAsync(@"https://discord.com/api/v6/users/@me/guilds");
jsonContent = await guildsResponse.Content.ReadAsStringAsync();
0
votes

Did you try the method .guilds from discord.js