From c355236f7f3bc7de5f421155c5ace870ff399180 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Sun, 16 Jun 2019 10:07:32 +0200 Subject: [PATCH] feat(Emoji): backport delete method (#3343) This backports #1877 (c93c4ad21fc2272ab2269083dd94bbb6af4f7aa7) in a semver-minor manner. --- src/client/rest/RESTMethods.js | 2 +- src/structures/Emoji.js | 10 ++++++++++ src/structures/Guild.js | 6 +++++- typings/index.d.ts | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js index d0e9df3efddb..cf7fe82ec70b 100644 --- a/src/client/rest/RESTMethods.js +++ b/src/client/rest/RESTMethods.js @@ -754,7 +754,7 @@ class RESTMethods { deleteEmoji(emoji, reason) { return this.rest.makeRequest('delete', Endpoints.Guild(emoji.guild).Emoji(emoji.id), true, undefined, reason) - .then(() => this.client.actions.GuildEmojiDelete.handle(emoji).data); + .then(() => this.client.actions.GuildEmojiDelete.handle(emoji).emoji); } getGuildAuditLogs(guild, options = {}) { diff --git a/src/structures/Emoji.js b/src/structures/Emoji.js index 39bb5f5e1a00..f514b81f8a37 100644 --- a/src/structures/Emoji.js +++ b/src/structures/Emoji.js @@ -222,6 +222,16 @@ class Emoji { return this.edit({ roles: newRoles }); } + + /** + * Deletes the emoji. + * @param {string} [reason] Reason for deleting the emoji + * @returns {Promise} + */ + delete(reason) { + return this.client.rest.methods.deleteEmoji(this, reason); + } + /** * When concatenated with a string, this automatically returns the emoji mention rather than the object. * @returns {string} diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 2fe5c64fba32..8b5214bb4a99 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -1322,11 +1322,12 @@ class Guild { * @param {Emoji|string} emoji The emoji to delete * @param {string} [reason] Reason for deleting the emoji * @returns {Promise} + * @deprecated */ deleteEmoji(emoji, reason) { if (typeof emoji === 'string') emoji = this.emojis.get(emoji); if (!(emoji instanceof Emoji)) throw new TypeError('Emoji must be either an instance of Emoji or an ID'); - return this.client.rest.methods.deleteEmoji(emoji, reason); + return emoji.delete(reason); } /** @@ -1595,4 +1596,7 @@ Guild.prototype.search = Guild.prototype.sync = util.deprecate(Guild.prototype.sync, 'Guild#sync:, userbot methods will be removed'); +Guild.prototype.deleteEmoji = + util.deprecate(Guild.prototype.deleteEmoji, 'Guild#deleteEmoji: use Emoji#delete instead'); + module.exports = Guild; diff --git a/typings/index.d.ts b/typings/index.d.ts index 2cd2be09b498..cb23635e3cfe 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -420,6 +420,7 @@ declare module 'discord.js' { public addRestrictedRoles(roles: Role[]): Promise; public edit(data: EmojiEditData, reason?: string): Promise; public equals(other: Emoji | object): boolean; + public delete(reason?: string): Promise; public fetchAuthor(): Promise; public removeRestrictedRole(role: Role): Promise; public removeRestrictedRoles(roles: Role[]): Promise;