mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
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:
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user