Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix target id being None raising an error #10060

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions discord/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,14 +799,12 @@ def created_at(self) -> datetime.datetime:

@utils.cached_property
def target(self) -> TargetType:
if self.action.target_type is None:
if self.action.target_type is None or self._target_id is None:
return None

try:
converter = getattr(self, '_convert_target_' + self.action.target_type)
except AttributeError:
if self._target_id is None:
return None
return Object(id=self._target_id)
else:
return converter(self._target_id)
Expand Down Expand Up @@ -874,7 +872,12 @@ def _convert_target_invite(self, target_id: None) -> Invite:
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 action type does 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]:
Expand Down
Loading