From 3b84f43303c9668aee8d5ea5138cf0d336f1d911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Landr=C3=A9?= <68849024+DevNono@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:02:51 +0100 Subject: [PATCH] fix: discord logs (#198) --- src/utils/discord.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/utils/discord.ts b/src/utils/discord.ts index 25293917..3a79e09b 100644 --- a/src/utils/discord.ts +++ b/src/utils/discord.ts @@ -127,13 +127,31 @@ export const syncRoles = async () => { // If the member doesn't have the tournament role, add it if (!member.roles.includes(tournament.discordRoleId)) { logger.debug(`Add ${tournament.id} tournament role to ${user.username}`); - await addMemberRole(member.user.id, tournament.discordRoleId); + try { + await addMemberRole(member.user.id, tournament.discordRoleId); + } catch (error) { + if (!error.response || error.response.status !== 404) throw error; + // Uh uh... It seems the discord member doesn't exist + // Or the role has been deleted - but don't care as we wanted to add it + // You have left the server. How dare you ?! + + logger.error(`Cannot add ${tournament.id} tournament role to ${user.username}`); + } } // If the team has a role id (not for discord roles) and the member doesn't have it, add it if (team.discordRoleId && !member.roles.includes(team.discordRoleId)) { logger.debug(`Add ${team.name} team (${tournament.id}) role to ${user.username}`); - await addMemberRole(member.user.id, team.discordRoleId); + try { + await addMemberRole(member.user.id, team.discordRoleId); + } catch (error) { + if (!error.response || error.response.status !== 404) throw error; + // Uh uh... It seems the discord member doesn't exist + // Or the role has been deleted - but don't care as we wanted to add it + // You have left the server. How dare you ?! + + logger.error(`Cannot add ${team.name} team (${tournament.id}) role to ${user.username}`); + } } } }