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
This commit is contained in:
Frangu Vlad
2018-07-31 19:43:17 +03:00
committed by Isabella
parent 88616eaf3e
commit 4ae58f66f4

View File

@@ -23,21 +23,21 @@ class GuildEmoji extends Emoji {
} }
_patch(data) { _patch(data) {
this.name = data.name; if (data.name) this.name = data.name;
/** /**
* Whether or not this emoji requires colons surrounding it * Whether or not this emoji requires colons surrounding it
* @type {boolean} * @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 * Whether this emoji is managed by an external service
* @type {boolean} * @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() { _clone() {
@@ -114,14 +114,15 @@ class GuildEmoji extends Emoji {
* .catch(console.error); * .catch(console.error);
*/ */
edit(data, reason) { 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) return this.client.api.guilds(this.guild.id).emojis(this.id)
.patch({ data: { .patch({ data: {
name: data.name, name: data.name,
roles: data.roles ? data.roles.map(r => r.id ? r.id : r) : undefined, roles,
}, reason }) }, reason })
.then(() => { .then(newData => {
const clone = this._clone(); const clone = this._clone();
clone._patch(data); clone._patch(newData);
return clone; return clone;
}); });
} }