diff options
| author | Rapptz <[email protected]> | 2020-11-23 05:24:13 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-11-23 05:24:13 -0500 |
| commit | 7a3a571e0a641aaeb061e86d8a6e851c5cd4c381 (patch) | |
| tree | d3e324f415ee3c4619121ed08f323aaea848f028 | |
| parent | Add sticker support (diff) | |
| download | discord.py-7a3a571e0a641aaeb061e86d8a6e851c5cd4c381.tar.xz discord.py-7a3a571e0a641aaeb061e86d8a6e851c5cd4c381.zip | |
Don't store a user cache if there's no member intent or cache is off
Without a cache or member intent the user cache can get out of date
with no events to update the underlying user in the member object.
Ref: #6034
| -rw-r--r-- | discord/flags.py | 4 | ||||
| -rw-r--r-- | discord/state.py | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/discord/flags.py b/discord/flags.py index 0cc106e5..cd8557a3 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -851,6 +851,10 @@ class MemberCacheFlags(BaseFlags): self.value = self.DEFAULT_VALUE return self + @property + def _empty(self): + return self.value == self.DEFAULT_VALUE + @flag_value def online(self): """:class:`bool`: Whether to cache members with a status. diff --git a/discord/state.py b/discord/state.py index 54de09cd..838a8f45 100644 --- a/discord/state.py +++ b/discord/state.py @@ -186,6 +186,9 @@ class ConnectionState: self._status = status self._intents = intents + if not intents.members or cache_flags._empty: + self.store_user = self.store_user_no_intents + self.parsers = parsers = {} for attr, func in inspect.getmembers(self): if attr.startswith('parse_'): @@ -279,6 +282,9 @@ class ConnectionState: self._users[user_id] = user return user + def store_user_no_intents(self, data): + return User(state=self, data=data) + def get_user(self, id): return self._users.get(id) |