mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 10:03:31 +01:00
Add support to edit emojis (#1142)
* Add support to edit emojis * Fixes for coding style. * Add and use guildEmoji constants for updateEmoji * Just use the Constant * Fix typo in edit documentation * Specify property types * Fix ridiculous typo. * Update Emoji.js
This commit is contained in:
@@ -123,6 +123,7 @@ class ClientDataManager {
|
||||
const oldEmoji = cloneObject(currentEmoji);
|
||||
currentEmoji.setup(newData);
|
||||
this.client.emit(Constants.Events.GUILD_EMOJI_UPDATE, oldEmoji, currentEmoji);
|
||||
return currentEmoji;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@ const Action = require('./Action');
|
||||
|
||||
class GuildEmojiUpdateAction extends Action {
|
||||
handle(oldEmoji, newEmoji) {
|
||||
this.client.dataManager.updateEmoji(oldEmoji, newEmoji);
|
||||
const emoji = this.client.dataManager.updateEmoji(oldEmoji, newEmoji);
|
||||
return {
|
||||
emoji,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -564,6 +564,14 @@ class RESTMethods {
|
||||
.then(data => this.client.actions.GuildEmojiCreate.handle(data, guild).emoji);
|
||||
}
|
||||
|
||||
updateEmoji(emoji, _data) {
|
||||
const data = {};
|
||||
if (_data.name) data.name = _data.name;
|
||||
if (_data.roles) data.roles = _data.roles.map(r => r.id ? r.id : r);
|
||||
return this.rest.makeRequest('patch', Constants.Endpoints.guildEmoji(emoji.guild.id, emoji.id), true, data)
|
||||
.then(newEmoji => this.client.actions.GuildEmojiUpdate.handle(emoji, newEmoji).emoji);
|
||||
}
|
||||
|
||||
deleteEmoji(emoji) {
|
||||
return this.rest.makeRequest('delete', `${Constants.Endpoints.guildEmojis(emoji.guild.id)}/${emoji.id}`, true)
|
||||
.then(() => this.client.actions.GuildEmojiDelete.handle(emoji).data);
|
||||
|
||||
Reference in New Issue
Block a user