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: Make AuditLogEntry user/user_id optional #2079

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2048](https://github.com/Pycord-Development/pycord/pull/2048))
- Fixed the Slash command syncronization method `indiviual`.
([#1925](https://github.com/Pycord-Development/pycord/pull/1925))
- Fixed major TypeError when an AuditLogEntry has no user.
([#2079](https://github.com/Pycord-Development/pycord/pull/2079))

## [2.4.1] - 2023-03-20

Expand Down
2 changes: 1 addition & 1 deletion discord/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class AuditLogEntry(Hashable):
-----------
action: :class:`AuditLogAction`
The action that was done.
user: :class:`abc.User`
user: Optional[:class:`abc.User`]
The user who initiated this action. Usually a :class:`Member`\, unless gone
then it's a :class:`User`.
id: :class:`int`
Expand Down
6 changes: 4 additions & 2 deletions discord/raw_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@
The entry ID.
guild_id: :class:`int`
The ID of the guild this action came from.
user_id: :class:`int`
user_id: Optional[:class:`int`]
The ID of the user who initiated this action.
target_id: Optional[:class:`int`]
The ID of the target that got changed.
Expand Down Expand Up @@ -708,7 +708,9 @@

def __init__(self, data: AuditLogEntryEvent) -> None:
self.id = int(data["id"])
self.user_id = int(data["user_id"])
self.user_id = data.get("user_id")
if self.user_id:
self.user_id = int(self.user_id)

Check warning on line 713 in discord/raw_models.py

View check run for this annotation

Codecov / codecov/patch

discord/raw_models.py#L711-L713

Added lines #L711 - L713 were not covered by tests
self.guild_id = int(data["guild_id"])
self.target_id = data.get("target_id")
if self.target_id:
Expand Down
2 changes: 1 addition & 1 deletion discord/types/raw_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class ThreadMembersUpdateEvent(TypedDict):

class AuditLogEntryEvent(TypedDict):
id: Snowflake
user_id: Snowflake
user_id: NotRequired[Snowflake]
guild_id: Snowflake
target_id: NotRequired[Snowflake]
action_type: int
Expand Down