diff --git a/naff/api/events/processors/member_events.py b/naff/api/events/processors/member_events.py index 367aa38d8..d5a2e9bb4 100644 --- a/naff/api/events/processors/member_events.py +++ b/naff/api/events/processors/member_events.py @@ -25,9 +25,13 @@ async def _on_raw_guild_member_add(self, event: "RawGatewayEvent") -> None: async def _on_raw_guild_member_remove(self, event: "RawGatewayEvent") -> None: g_id = event.data.pop("guild_id") user = self.cache.place_user_data(event.data["user"]) + member = self.cache.get_member(g_id, user.id) + + self.cache.delete_member(g_id, user.id) guild = self.cache.get_guild(g_id) guild.member_count -= 1 - self.dispatch(events.MemberRemove(g_id, self.cache.get_member(g_id, user.id) or user)) + + self.dispatch(events.MemberRemove(g_id, member or user)) @Processor.define() async def _on_raw_guild_member_update(self, event: "RawGatewayEvent") -> None: diff --git a/naff/client/smart_cache.py b/naff/client/smart_cache.py index f4c579d26..df7e435b5 100644 --- a/naff/client/smart_cache.py +++ b/naff/client/smart_cache.py @@ -231,7 +231,9 @@ def delete_member(self, guild_id: "Snowflake_Type", user_id: "Snowflake_Type") - user_id = to_snowflake(user_id) guild_id = to_snowflake(guild_id) - self.member_cache.pop((guild_id, user_id), None) + if member := self.member_cache.pop((guild_id, user_id), None): + member.guild._member_ids.discard(user_id) + self.delete_user_guild(user_id, guild_id) def place_user_guild(self, user_id: "Snowflake_Type", guild_id: "Snowflake_Type") -> None: