From 4ae58f66f4b46e789b3eb050f1dca9e09db71e0a Mon Sep 17 00:00:00 2001 From: Frangu Vlad Date: Tue, 31 Jul 2018 19:43:17 +0300 Subject: [PATCH] fix: Wrong _patch call from GuildEmoji#edit and other issues (#2673) * Fix bugs * Make the data.roles be undefined before API call * Suggested changes * Handle edit properly --- src/structures/GuildEmoji.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/structures/GuildEmoji.js b/src/structures/GuildEmoji.js index 4811f207e..e9fde762a 100644 --- a/src/structures/GuildEmoji.js +++ b/src/structures/GuildEmoji.js @@ -23,21 +23,21 @@ class GuildEmoji extends Emoji { } _patch(data) { - this.name = data.name; + if (data.name) this.name = data.name; /** * Whether or not this emoji requires colons surrounding it * @type {boolean} */ - this.requiresColons = data.require_colons; + if (typeof data.require_colons !== 'undefined') this.requiresColons = data.require_colons; /** * Whether this emoji is managed by an external service * @type {boolean} */ - this.managed = data.managed; + if (typeof data.managed !== 'undefined') this.managed = data.managed; - if (data.roles) this.roles._patch(data.roles); + if (data.roles) this._roles = data.roles; } _clone() { @@ -114,14 +114,15 @@ class GuildEmoji extends Emoji { * .catch(console.error); */ edit(data, reason) { + const roles = data.roles ? data.roles.map(r => r.id || r) : undefined; return this.client.api.guilds(this.guild.id).emojis(this.id) .patch({ data: { name: data.name, - roles: data.roles ? data.roles.map(r => r.id ? r.id : r) : undefined, + roles, }, reason }) - .then(() => { + .then(newData => { const clone = this._clone(); - clone._patch(data); + clone._patch(newData); return clone; }); }