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(state): hard crash when user_id is None #1014

Merged
merged 4 commits into from Apr 5, 2023
Merged

Conversation

Miolus
Copy link
Contributor

@Miolus Miolus commented Mar 20, 2023

Reflect https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object

Summary

Fix issue like detailed in https://discord.com/channels/881118111967883295/1084474550345023638

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
    • I have run task pyright and fixed the relevant issues.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

nextcord/state.py Outdated Show resolved Hide resolved
Co-authored-by: toolifelesstocode <toolifelesstocode@gmail.com>
@ooliver1 ooliver1 requested a review from spifory March 20, 2023 23:31
Copy link
Collaborator

@spifory spifory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm if it's been tested

@EmreTech EmreTech changed the title Fix hard crash when user_id is None fix: hard crash when user_id is None Mar 22, 2023
@EmreTech EmreTech added t: bug Type: bug - something isn't working p: high Priority: high - should be worked on as soon as reasonable s: awaiting review Status: the issue or PR is awaiting reviews labels Mar 22, 2023
@EmreTech EmreTech changed the title fix: hard crash when user_id is None fix(on_guild_audit_log_entry_create): hard crash when user_id is None Mar 22, 2023
@ooliver1 ooliver1 changed the title fix(on_guild_audit_log_entry_create): hard crash when user_id is None fix(state): hard crash when user_id is None Mar 27, 2023
nextcord/state.py Outdated Show resolved Hide resolved
@ooliver1
Copy link
Member

ooliver1 commented Apr 5, 2023

In the future I would recommend using a separate branch in your fork other than master.

@ooliver1 ooliver1 requested a review from Skelmis April 5, 2023 14:40
Copy link
Collaborator

@alentoghostflame alentoghostflame left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested, but looks good to me. This properly reflects ddocs listing user_id as a nullable field.

@ooliver1 ooliver1 removed the request for review from Skelmis April 5, 2023 17:21
@ooliver1 ooliver1 merged commit 2eed4e6 into nextcord:master Apr 5, 2023
8 checks passed
ooliver1 added a commit that referenced this pull request Apr 5, 2023
* Fix hard crash when user_id is None

Reflect https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object

* Change to literal key word

Co-authored-by: toolifelesstocode <toolifelesstocode@gmail.com>

* refactor(state): use data.get("user_id") for cheaner checks

* fix(state): ignore if user is None in audit log entry

---------

Co-authored-by: toolifelesstocode <toolifelesstocode@gmail.com>
Co-authored-by: Oliver Wilkes <oliverwilkes2006@icloud.com>
@shahriyardx
Copy link

After this there is a new error

Traceback (most recent call last):
  File "/myBot/bot.py", line 214, in <module>
    bot.run(os.environ["TOKEN"])
  File "/myBot/venv/lib/python3.8/site-packages/nextcord/client.py", line 871, in run
    return future.result()
  File "/myBot/venv/lib/python3.8/site-packages/nextcord/client.py", line 850, in runner
    await self.start(*args, **kwargs)
  File "/myBot/venv/lib/python3.8/site-packages/nextcord/client.py", line 814, in start
    await self.connect(reconnect=reconnect)
  File "/myBot/venv/lib/python3.8/site-packages/nextcord/shard.py", line 511, in connect
    raise item.error
  File "/myBot/venv/lib/python3.8/site-packages/nextcord/shard.py", line 152, in worker
    await self.ws.poll_event()
  File "/myBot/venv/lib/python3.8/site-packages/nextcord/gateway.py", line 603, in poll_event
    await self.received_message(msg.data)
  File "/myBot/venv/lib/python3.8/site-packages/nextcord/gateway.py", line 553, in received_message
    func(data)
  File "/myBot/venv/lib/python3.8/site-packages/nextcord/state.py", line 2318, in parse_guild_audit_log_entry_create
    entry = AuditLogEntry(auto_moderation_rules={}, users=users, data=data, guild=guild)
  File "/myBot/venv/lib/python3.8/site-packages/nextcord/audit_logs.py", line 457, in __init__
    self._from_data(data)
  File "/myBot/venv/lib/python3.8/site-packages/nextcord/audit_logs.py", line 519, in _from_data
    channel_id = int(self.extra["channel_id"])
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

@EmreTech EmreTech removed the s: awaiting review Status: the issue or PR is awaiting reviews label Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p: high Priority: high - should be worked on as soon as reasonable t: bug Type: bug - something isn't working
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants