From 36fae98a05d0acad5dc63786548dab274f8b7aa0 Mon Sep 17 00:00:00 2001 From: Skillz Date: Fri, 28 Aug 2020 13:46:41 -0400 Subject: [PATCH] better reaction handling --- src/handlers/message.ts | 14 ++++++++++++++ src/types/errors.ts | 1 + 2 files changed, 15 insertions(+) diff --git a/src/handlers/message.ts b/src/handlers/message.ts index b2898d258..da9d90db2 100644 --- a/src/handlers/message.ts +++ b/src/handlers/message.ts @@ -65,6 +65,16 @@ export function addReaction( messageID: string, reaction: string, ) { + if (!botHasChannelPermissions(channelID, [Permissions.ADD_REACTIONS])) { + throw new Error(Errors.MISSING_ADD_REACTIONS); + } + + if ( + !botHasChannelPermissions(channelID, [Permissions.READ_MESSAGE_HISTORY]) + ) { + throw new Error(Errors.MISSING_READ_MESSAGE_HISTORY); + } + return RequestManager.put( endpoints.CHANNEL_MESSAGE_REACTION_ME( channelID, @@ -114,6 +124,10 @@ export function removeUserReaction( reaction: string, userID: string, ) { + if (!botHasChannelPermissions(channelID, [Permissions.MANAGE_MESSAGES])) { + throw new Error(Errors.MISSING_MANAGE_MESSAGES); + } + RequestManager.delete( endpoints.CHANNEL_MESSAGE_REACTION_USER( channelID, diff --git a/src/types/errors.ts b/src/types/errors.ts index 7e160d49f..da321ff35 100644 --- a/src/types/errors.ts +++ b/src/types/errors.ts @@ -17,6 +17,7 @@ export enum Errors { MISSING_MANAGE_GUILD = "MISSING_MANAGE_GUILD", MISSING_VIEW_AUDIT_LOG = "MISSING_VIEW_AUDIT_LOG", MISSING_EMBED_LINKS = "MISSING_EMBED_LINKS", + MISSING_ADD_REACTIONS = "MISSING_ADD_REACTIONS", DELETE_MESSAGES_MIN = "DELETE_MESSAGES_MIN", MESSAGE_MAX_LENGTH = "MESSAGE_MAX_LENGTH", NICKNAMES_MAX_LENGTH = "NICKNAMES_MAX_LENGTH",