Skip to content

Commit

Permalink
GuildEmoji.fetchAuthor() error handling (#2788)
Browse files Browse the repository at this point in the history
* handle when client has insufficient permissions, add typing

* code review
  • Loading branch information
cas-c authored and iCrawl committed Sep 1, 2018
1 parent be4d6f9 commit 314161a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/errors/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',

Expand Down
2 changes: 2 additions & 0 deletions src/structures/GuildEmoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ declare module 'discord.js' {
public delete(reason?: string): Promise<GuildEmoji>;
public edit(data: GuildEmojiEditData, reason?: string): Promise<GuildEmoji>;
public equals(other: GuildEmoji | object): boolean;
public fetchAuthor(): Promise<User>;
public setName(name: string, reason?: string): Promise<GuildEmoji>;
}

Expand Down

0 comments on commit 314161a

Please sign in to comment.