diff --git a/interactions/client/client.py b/interactions/client/client.py index 3c4fed523..0407fc69c 100644 --- a/interactions/client/client.py +++ b/interactions/client/client.py @@ -534,6 +534,16 @@ def guilds(self) -> List["Guild"]: """Returns a list of all guilds the bot is in.""" return self.user.guilds + @property + def guild_count(self) -> int: + """ + Returns the number of guilds the bot is in. + + This function is faster than using `len(client.guilds)` as it does not require using the cache. + As such, this is preferred when you only need the count of guilds. + """ + return self.user.guild_count + @property def status(self) -> Status: """ diff --git a/interactions/ext/debug_extension/__init__.py b/interactions/ext/debug_extension/__init__.py index b018448a8..d05050b90 100644 --- a/interactions/ext/debug_extension/__init__.py +++ b/interactions/ext/debug_extension/__init__.py @@ -76,7 +76,7 @@ async def debug_info(self, ctx: InteractionContext) -> None: e.add_field("Loaded Exts", ", ".join(self.bot.ext)) - e.add_field("Guilds", str(len(self.bot.guilds))) + e.add_field("Guilds", str(self.bot.guild_count)) await ctx.send(embeds=[e]) diff --git a/interactions/models/discord/user.py b/interactions/models/discord/user.py index bfe62efeb..0ac24ba35 100644 --- a/interactions/models/discord/user.py +++ b/interactions/models/discord/user.py @@ -239,6 +239,16 @@ def guilds(self) -> List["Guild"]: """The guilds the user is in.""" return list(filter(None, (self._client.cache.get_guild(guild_id) for guild_id in self._guild_ids))) + @property + def guild_count(self) -> int: + """ + Returns the number of guilds the bot is in. + + This function is faster than using `len(client_user.guilds)` as it does not require using the cache. + As such, this is preferred when you only need the count of guilds. + """ + return len(self._guild_ids or ()) + async def edit( self, *, diff --git a/interactions/models/discord/user.pyi b/interactions/models/discord/user.pyi index f84af990d..c0dfdece9 100644 --- a/interactions/models/discord/user.pyi +++ b/interactions/models/discord/user.pyi @@ -95,6 +95,8 @@ class ClientUser(User): def _add_guilds(self, guild_ids: Set["Snowflake_Type"]) -> None: ... @property def guilds(self) -> List["Guild"]: ... + @property + def guild_count(self) -> int: ... async def edit( self, *,