From c9df84b2553313c94b4dc81d30d398070bfb8abc Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 00:06:57 +0100 Subject: [PATCH] Fix crash when getting a channel that doesn't exist --- src/tools/discord.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tools/discord.ts b/src/tools/discord.ts index 00bbc1d..1bec92b 100644 --- a/src/tools/discord.ts +++ b/src/tools/discord.ts @@ -2,11 +2,15 @@ import { GuildBasedChannel, GuildTextBasedChannel, PermissionsBitField } from "d import client from "../client"; export async function getGuildChannel(guildID: string, channelID: string): Promise { - const guild = await client.guilds.fetch(guildID); - if (!guild) return null; + try { + const guild = await client.guilds.fetch(guildID); + if (!guild) return null; - const channel = await guild.channels.fetch(channelID); - return channel; + const channel = await guild.channels.fetch(channelID); + return channel; + } catch (_error) { + return null; + } } export async function getChannelPermission(channel: GuildTextBasedChannel): Promise | null> {