Skip to content

feat: add guild_count property #1743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions interactions/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
2 changes: 1 addition & 1 deletion interactions/ext/debug_extension/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
10 changes: 10 additions & 0 deletions interactions/models/discord/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
*,
Expand Down
2 changes: 2 additions & 0 deletions interactions/models/discord/user.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
*,
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy