Browse Source

Fix crash from Discord sending null channel_id for automod audit logs

pull/10109/head
Rapptz 2 years ago
committed by dolfies
parent
commit
1a4b2b7440
  1. 10
      discord/audit_logs.py

10
discord/audit_logs.py

@ -485,7 +485,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):
@ -604,13 +604,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_'):

Loading…
Cancel
Save