From 474a35a736002ded424d89e0022972f1ec92f75b Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Mon, 5 Feb 2024 21:11:59 +0100 Subject: [PATCH] error handling on reaction roles --- events/reactionAdd.js | 12 +++++++++--- events/reactionRemove.js | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/events/reactionAdd.js b/events/reactionAdd.js index 6207c40..536b61d 100644 --- a/events/reactionAdd.js +++ b/events/reactionAdd.js @@ -37,7 +37,13 @@ export async function execute(reaction, user) { const role = await guild.roles.fetch(rep.role); if (role === null) return; - // Add role to user - await guild.members.addRole({ role, user }); - console.info(`[INFO] Added role with id '${role.id}' to user '${user.username}'.`); + try { + // Add role to user + await guild.members.addRole({ role, user }); + console.info(`[INFO] Added role with id '${role.id}' to user '${user.username}'.`); + } catch (error) { + // Missing permissions + console.error(error); + await user.send('Unable to assign role. Please contact server staff.'); + } } diff --git a/events/reactionRemove.js b/events/reactionRemove.js index 2888bf9..0cc52f1 100644 --- a/events/reactionRemove.js +++ b/events/reactionRemove.js @@ -33,7 +33,13 @@ export async function execute(reaction, user) { const role = await guild.roles.fetch(rep.role); if (role === null) return; - // Add role to user - await guild.members.removeRole({ role, user }); - console.info(`[INFO] Removed role with id '${role.id}' from user '${user.username}'.`); + try { + // Remove role from user + await guild.members.removeRole({ role, user }); + console.info(`[INFO] Removed role with id '${role.id}' from user '${user.username}'.`); + } catch (error) { + // Missing permissions + console.error(error); + await user.send('Unable to retract role. Please contact server staff.'); + } }