From 51142743bce60d60ed89fddfbb6e319c643ffdfd Mon Sep 17 00:00:00 2001 From: Leonardo Date: Fri, 31 May 2024 04:52:19 +0200 Subject: [PATCH] Fix bug with cache superfluously incrementing role position --- discord/guild.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 59c216f2f..17f351b7a 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -432,27 +432,11 @@ class Guild(Hashable): return member, before, after def _add_role(self, role: Role, /) -> None: - # roles get added to the bottom (position 1, pos 0 is @everyone) - # so since self.roles has the @everyone role, we can't increment - # its position because it's stuck at position 0. Luckily x += False - # is equivalent to adding 0. So we cast the position to a bool and - # increment it. - for r in self._roles.values(): - r.position += not r.is_default() - self._roles[role.id] = role def _remove_role(self, role_id: int, /) -> Role: # this raises KeyError if it fails.. - role = self._roles.pop(role_id) - - # since it didn't, we can change the positions now - # basically the same as above except we only decrement - # the position if we're above the role we deleted. - for r in self._roles.values(): - r.position -= r.position > role.position - - return role + return self._roles.pop(role_id) @classmethod def _create_unavailable(cls, *, state: ConnectionState, guild_id: int, data: Optional[Dict[str, Any]]) -> Guild: