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(UserUpdateAction): rely on client.user when ids match #6511

Merged
merged 1 commit into from Aug 24, 2021
Merged

fix(UserUpdateAction): rely on client.user when ids match #6511

merged 1 commit into from Aug 24, 2021

Conversation

kevinbioj
Copy link
Contributor

Please describe the changes this PR makes and why it should be merged:

When the UserManager cache is disabled, updating the client user will result in a crash. The user update action gets the old state of the user via the UserManager cache, even if it's the client user. However, when it's disabled, nothing is being returned and so newUser._update throws a type error.

This fix makes the code get client.user if client.user.id and data.id are equal.

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

@SpaceEEC SpaceEEC linked an issue Aug 23, 2021 that may be closed by this pull request
@iShibi
Copy link
Contributor

iShibi commented Aug 23, 2021

What if the UserUpdate gets triggered by a non-client user who isn't cached? The newUser will be undefined in that case too and the same error will occur. I think you should use the getUser method here.

@iShibi
Copy link
Contributor

iShibi commented Aug 23, 2021

There is a chance that getUser will too return undefined if the client didn't opt for USER partial. The GuildMemberUpdate action handler does it the right way.

@kevinbioj
Copy link
Contributor Author

kevinbioj commented Aug 23, 2021

There is a chance that getUser will too return undefined if the client didn't opt for USER partial. The GuildMemberUpdate action handler does it the right way.

Discord's USER_UPDATE is only emitted for client user's changes. Changes for other users have to go through the GUILD_MEMBER_UPDATE event, where the UserUpdate action is not being called if the user wasn't in cache already.

That means if this action is being called by anything else than the actual USER_UPDATE event, the user is in the cache (logic in GuildMemberUpdate action, and the PresenceUpdate action performs a User#equals using the same data, meaning the action is never being called). Which also means the only user that may not be at this point, is the client user.

Now, if people have been messing enough with the caches, the library shouldn't be handling that for them. Enabling the GUILD_MEMBERS intent and disabling the GuildManager or the UserManager cache(s) is definitely going to lead to undefined behaviors but would be up to the end user responsibility imo.

The client user would be the only exception to that rule as the action is being called no matter what intents are being enabled. Which would mean the crash would occur as soon as the UserManager is disabled (#6510).

That's mainly why I haven't gotten further in the patch, thought that wouldn't be "that useful". That's also why I'd like to hear some maintainers point-of-views because I must admit I'm not very confident on that particular point.

@kyranet kyranet requested a review from iCrawl August 23, 2021 16:58
@iCrawl iCrawl added this to the Version 13.2 milestone Aug 24, 2021
@iCrawl iCrawl merged commit 1418649 into discordjs:main Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bot crash while it updates itself
5 participants