Skip to content

Commit

Permalink
fix(userUpdate): Uncached users throwing undefined (#1366)
Browse files Browse the repository at this point in the history
Co-authored-by: Bsian <chharry321@gmail.com>
  • Loading branch information
Dramex and bsian03 authored May 10, 2022
1 parent b485352 commit c223725
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ class Shard extends EventEmitter {
* Fired when a user's avatar, discriminator or username changes
* @event Client#userUpdate
* @prop {User} user The updated user
* @prop {Object?} oldUser The old user data
* @prop {Object?} oldUser The old user data. If the user was uncached, this will be null
* @prop {String} oldUser.username The username of the user
* @prop {String} oldUser.discriminator The discriminator of the user
* @prop {String?} oldUser.avatar The hash of the user's avatar, or null if no avatar
Expand Down Expand Up @@ -1959,13 +1959,17 @@ class Shard extends EventEmitter {
break;
}
case "USER_UPDATE": {
const user = this.client.users.get(packet.d.id);
const oldUser = {
username: user.username,
discriminator: user.discriminator,
avatar: user.avatar
};
this.emit("userUpdate", user.update(packet.d), oldUser);
let user = this.client.users.get(packet.d.id);
let oldUser = null;
if(user) {
oldUser = {
username: user.username,
discriminator: user.discriminator,
avatar: user.avatar
};
}
user = this.client.users.update(packet.d, this.client);
this.emit("userUpdate", user, oldUser);
break;
}
case "RELATIONSHIP_ADD": {
Expand Down

0 comments on commit c223725

Please sign in to comment.