From a5c94952843cb286942b746222b3bdba51734aec Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 21 Mar 2023 10:28:39 +0000 Subject: [PATCH] fix(ClientUser): no mutation on edit --- packages/discord.js/src/structures/ClientUser.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/discord.js/src/structures/ClientUser.js b/packages/discord.js/src/structures/ClientUser.js index 8e854f16c818..040e732910c2 100644 --- a/packages/discord.js/src/structures/ClientUser.js +++ b/packages/discord.js/src/structures/ClientUser.js @@ -54,12 +54,14 @@ class ClientUser extends User { * @param {ClientUserEditOptions} options The options to provide * @returns {Promise} */ - async edit(options) { - if (options.avatar !== undefined) options.avatar = await DataResolver.resolveImage(options.avatar); - const newData = await this.client.rest.patch(Routes.user(), { body: options }); - this.client.token = newData.token; - this.client.rest.setToken(newData.token); - const { updated } = this.client.actions.UserUpdate.handle(newData); + async edit({ username, avatar }) { + const data = await this.client.rest.patch(Routes.user(), { + body: { username, avatar: avatar && (await DataResolver.resolveImage(avatar)) }, + }); + + this.client.token = data.token; + this.client.rest.setToken(data.token); + const { updated } = this.client.actions.UserUpdate.handle(data); return updated ?? this; }