From 314161ab70ab2c7f59a0ebd02a391f8d86186cdc Mon Sep 17 00:00:00 2001 From: lipgloss Date: Fri, 31 Aug 2018 20:52:50 -0600 Subject: [PATCH] GuildEmoji.fetchAuthor() error handling (#2788) * handle when client has insufficient permissions, add typing * code review --- src/errors/Messages.js | 2 ++ src/structures/GuildEmoji.js | 2 ++ typings/index.d.ts | 1 + 3 files changed, 5 insertions(+) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index 00f99a676..80fa7e389 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -95,6 +95,8 @@ const Messages = { EMOJI_TYPE: 'Emoji must be a string or GuildEmoji/ReactionEmoji', EMOJI_MANAGED: 'Emoji is managed and has no Author.', + MISSING_MANAGE_EMOJIS_PERMISSION: + guild => `Client must have Manage Emoji permission in guild ${guild} to see emoji authors.`, REACTION_RESOLVE_USER: 'Couldn\'t resolve the user ID to remove from the reaction.', diff --git a/src/structures/GuildEmoji.js b/src/structures/GuildEmoji.js index e9fde762a..20e48aa06 100644 --- a/src/structures/GuildEmoji.js +++ b/src/structures/GuildEmoji.js @@ -90,6 +90,8 @@ class GuildEmoji extends Emoji { fetchAuthor() { if (this.managed) { return Promise.reject(new Error('EMOJI_MANAGED')); + } else if (!this.guild.me.permissions.has(Permissions.FLAGS.MANAGE_EMOJIS)) { + return Promise.reject(new Error('MISSING_MANAGE_EMOJIS_PERMISSION', this.guild)); } return this.client.api.guilds(this.guild.id).emojis(this.id).get() .then(emoji => this.client.users.add(emoji.user)); diff --git a/typings/index.d.ts b/typings/index.d.ts index 12f38f31e..808fcf6e4 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -545,6 +545,7 @@ declare module 'discord.js' { public delete(reason?: string): Promise; public edit(data: GuildEmojiEditData, reason?: string): Promise; public equals(other: GuildEmoji | object): boolean; + public fetchAuthor(): Promise; public setName(name: string, reason?: string): Promise; }