Skip to content

Commit 5caee7e

Browse files
committed
fix(implement:AutoMod): Fixed crash in update when rule is not in cache
1 parent c0ab20a commit 5caee7e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

discord/state.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,9 +1249,10 @@ def parse_auto_moderation_rule_create(self, data):
12491249

12501250
def parse_auto_moderation_rule_update(self, data):
12511251
guild = self._get_guild(int(data['guild_id']))
1252+
rule_id = int(data['id'])
12521253
if guild is not None:
1254+
old_rule = guild._automod_rules.pop(rule_id, None)
12531255
rule = AutoModRule(state=self, guild=guild, **data)
1254-
old_rule = guild._automod_rules.pop(rule.id)
12551256
guild._add_automod_rule(rule)
12561257
self.dispatch('automod_rule_update', old_rule, rule)
12571258
else:

docs/api.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,11 @@ to handle it, which defaults to print a traceback and ignoring the exception.
927927

928928
:param before: The old rule.
929929
:type before: :class:`AutoModRule`
930+
931+
.. warning::
932+
933+
This will be :obj:`None` if the rule was not in the cache before.
934+
930935
:param after: The updated rule.
931936
:type after: :class:`AutoModRule`
932937

0 commit comments

Comments
 (0)