feat(Emoji): backport delete method (#3343)

This backports #1877 (c93c4ad21f) in a semver-minor manner.
This commit is contained in:
SpaceEEC
2019-06-16 10:07:32 +02:00
committed by GitHub
parent b8924369ea
commit c355236f7f
4 changed files with 17 additions and 2 deletions

View File

@@ -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 = {}) {

View File

@@ -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}

View File

@@ -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;

1
typings/index.d.ts vendored
View File

@@ -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>;