Skip to content

Commit

Permalink
fix: filter out cache misses from guild properties (#1454)
Browse files Browse the repository at this point in the history
* fix: filter out cache misses from Guild.members

* fix: filter out cache misses from Guild.roles

---------

Co-authored-by: Astrea49 <25420078+Astrea49@users.noreply.github.com>
  • Loading branch information
AstreaTSS and AstreaTSS authored Jun 21, 2023
1 parent 1bd1100 commit 5a29624
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions interactions/models/discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ def threads(self) -> List["models.TYPE_THREAD_CHANNEL"]:
@property
def members(self) -> List["models.Member"]:
"""Returns a list of all members within this guild."""
return [self._client.cache.get_member(self.id, m_id) for m_id in self._member_ids]
members = (self._client.cache.get_member(self.id, m_id) for m_id in self._member_ids)
return [m for m in members if m]

@property
def premium_subscribers(self) -> List["models.Member"]:
Expand All @@ -368,7 +369,8 @@ def humans(self) -> List["models.Member"]:
@property
def roles(self) -> List["models.Role"]:
"""Returns a list of roles associated with this guild."""
return sorted([self._client.cache.get_role(r_id) for r_id in self._role_ids], reverse=True)
roles = sorted((self._client.cache.get_role(r_id) for r_id in self._role_ids), reverse=True)
return [r for r in roles if r]

@property
def me(self) -> "models.Member":
Expand Down

1 comment on commit 5a29624

@AstreaTSS
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out the roles filtering is still kind of flawed, oops--

Please sign in to comment.