From ebc1bc3cbb2bccc66d9cb7fd97944507b4105303 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 28 Mar 2023 04:10:59 -0400 Subject: [PATCH] Fix crash from Discord sending null channel_id for automod audit logs --- discord/audit_logs.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/discord/audit_logs.py b/discord/audit_logs.py index fe51b6106..47f397a8a 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -521,7 +521,7 @@ class _AuditLogProxyMessageBulkDelete(_AuditLogProxy): class _AuditLogProxyAutoModAction(_AuditLogProxy): automod_rule_name: str automod_rule_trigger_type: str - channel: Union[abc.GuildChannel, Thread] + channel: Optional[Union[abc.GuildChannel, Thread]] class AuditLogEntry(Hashable): @@ -644,13 +644,17 @@ class AuditLogEntry(Hashable): or self.action is enums.AuditLogAction.automod_flag_message or self.action is enums.AuditLogAction.automod_timeout_member ): - channel_id = int(extra['channel_id']) + channel_id = utils._get_as_snowflake(extra, 'channel_id') + channel = None + if channel_id is not None: + channel = self.guild.get_channel_or_thread(channel_id) or Object(id=channel_id) + self.extra = _AuditLogProxyAutoModAction( automod_rule_name=extra['auto_moderation_rule_name'], automod_rule_trigger_type=enums.try_enum( enums.AutoModRuleTriggerType, extra['auto_moderation_rule_trigger_type'] ), - channel=self.guild.get_channel_or_thread(channel_id) or Object(id=channel_id), + channel=channel, ) elif self.action.name.startswith('overwrite_'):