diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index 9e275724f..9bbdf7df3 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -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 @@ -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": {