Skip to content

Commit

Permalink
don't error if fetch failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Techbot121 authored and Meta Construct committed Nov 2, 2023
1 parent caa23a4 commit 55feedf
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions app/services/discord/modules/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,25 +217,26 @@ export default (bot: DiscordBot): void => {
switch (entry.targetType) {
case "ApplicationCommand": {
const command =
guild.commands.cache.get(Id) ?? (await guild.commands.fetch(Id));
guild.commands.cache.get(Id) ?? (await guild.commands.fetch(Id).catch());
target = command ? `</${command.name}:${command.id}>` : Id;
break;
}
case "AutoModerationRule": {
const rule =
guild.autoModerationRules.cache.get(Id) ??
(await guild.autoModerationRules.fetch(Id));
(await guild.autoModerationRules.fetch(Id).catch());
target = rule?.name ?? Id;
break;
}
case "Channel": {
const channel =
guild.channels.cache.get(Id) ?? (await guild.channels.fetch(Id));
guild.channels.cache.get(Id) ?? (await guild.channels.fetch(Id).catch());
target = channel ? `${channel} (${Id})` : Id;
break;
}
case "Emoji": {
const emoji = guild.emojis.cache.get(Id) ?? (await guild.emojis.fetch(Id));
const emoji =
guild.emojis.cache.get(Id) ?? (await guild.emojis.fetch(Id).catch());
target = emoji ? `${emoji.name} (${Id})` : Id;
break;
}
Expand All @@ -246,7 +247,7 @@ export default (bot: DiscordBot): void => {
case "GuildScheduledEvent": {
const event =
guild.scheduledEvents.cache.get(Id) ??
(await guild.scheduledEvents.fetch(Id));
(await guild.scheduledEvents.fetch(Id).catch());
target = event ? event.name : Id;
break;
}
Expand All @@ -256,7 +257,8 @@ export default (bot: DiscordBot): void => {
break;
}
case "Invite": {
const invite = guild.invites.cache.get(Id) ?? (await guild.invites.fetch(Id));
const invite =
guild.invites.cache.get(Id) ?? (await guild.invites.fetch(Id).catch());
target = invite ? `<@${invite.inviterId}> -> <#${invite.channelId}>` : Id;
break;
}
Expand All @@ -265,7 +267,7 @@ export default (bot: DiscordBot): void => {
break;
}
case "Role": {
const role = guild.roles.cache.get(Id) ?? (await guild.roles.fetch(Id));
const role = guild.roles.cache.get(Id) ?? (await guild.roles.fetch(Id).catch());
target = role ? `${role.toString()} (${Id})` : Id;
break;
}
Expand All @@ -277,7 +279,8 @@ export default (bot: DiscordBot): void => {
break;
}
case "Sticker": {
const sticker = guild.emojis.cache.get(Id) ?? (await guild.emojis.fetch(Id));
const sticker =
guild.emojis.cache.get(Id) ?? (await guild.emojis.fetch(Id).catch());
target = sticker ? `${sticker.name} (${Id})` : Id;
break;
}
Expand All @@ -288,7 +291,7 @@ export default (bot: DiscordBot): void => {
}
case "User":
const user =
guild.members.cache.get(Id) ?? (await guild.client.users.fetch(Id));
guild.members.cache.get(Id) ?? (await guild.client.users.fetch(Id).catch());
target = (user && user.mention) ?? `<@${Id}>`;
break;
case "Webhook":
Expand Down

0 comments on commit 55feedf

Please sign in to comment.