Skip to content

Commit

Permalink
fix: discord logs (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
DevNono authored Nov 21, 2023
1 parent b7f2ebb commit 3b84f43
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/utils/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
}
}
Expand Down

0 comments on commit 3b84f43

Please sign in to comment.