error handling on reaction roles

This commit is contained in:
Baipyrus 2024-02-05 21:11:59 +01:00
parent ddcec60be6
commit 474a35a736
2 changed files with 18 additions and 6 deletions

View File

@ -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.');
}
}

View File

@ -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.');
}
}