Skip to content

Commit

Permalink
feat(Emoji): backport delete method (#3343)
Browse files Browse the repository at this point in the history
This backports #1877 (c93c4ad) in a semver-minor manner.
  • Loading branch information
SpaceEEC committed Jun 16, 2019
1 parent b892436 commit c355236
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/client/rest/RESTMethods.js
Expand Up @@ -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 = {}) {
Expand Down
10 changes: 10 additions & 0 deletions src/structures/Emoji.js
Expand Up @@ -222,6 +222,16 @@ class Emoji {
return this.edit({ roles: newRoles });
}


/**
* Deletes the emoji.
* @param {string} [reason] Reason for deleting the emoji
* @returns {Promise<Emoji>}
*/
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}
Expand Down
6 changes: 5 additions & 1 deletion src/structures/Guild.js
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -420,6 +420,7 @@ declare module 'discord.js' {
public addRestrictedRoles(roles: Role[]): Promise<Emoji>;
public edit(data: EmojiEditData, reason?: string): Promise<Emoji>;
public equals(other: Emoji | object): boolean;
public delete(reason?: string): Promise<this>;
public fetchAuthor(): Promise<User>;
public removeRestrictedRole(role: Role): Promise<Emoji>;
public removeRestrictedRoles(roles: Role[]): Promise<Emoji>;
Expand Down

0 comments on commit c355236

Please sign in to comment.