From 88d7bd127587246829dbd8cfbb76bfef30ff5d2e Mon Sep 17 00:00:00 2001 From: iyad-f <128908811+iyad-f@users.noreply.github.com> Date: Sun, 9 Feb 2025 07:17:41 +0530 Subject: [PATCH] Fix message_pin, message_unpin target id being None MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michael H Co-authored-by: Alex Nørgaard --- discord/audit_logs.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/discord/audit_logs.py b/discord/audit_logs.py index 59d563829..af67855d4 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -874,7 +874,13 @@ class AuditLogEntry(Hashable): def _convert_target_emoji(self, target_id: int) -> Union[Emoji, Object]: return self._state.get_emoji(target_id) or Object(id=target_id, type=Emoji) - def _convert_target_message(self, target_id: int) -> Union[Member, User, Object]: + def _convert_target_message(self, target_id: Optional[int]) -> Optional[Union[Member, User, Object]]: + # The message_pin and message_unpin action types do not have a + # non-null target_id so safeguard against that + + if target_id is None: + return None + return self._get_member(target_id) or Object(id=target_id, type=Member) def _convert_target_stage_instance(self, target_id: int) -> Union[StageInstance, Object]: