Fix crash when getting a channel that doesn't exist

This commit is contained in:
Lukas | AstroGD 2022-11-29 00:06:57 +01:00
parent 0d69cf3e7b
commit c9df84b255
Signed by: AstroGD
GPG Key ID: 82A5E6C236C535AA

View File

@ -2,11 +2,15 @@ import { GuildBasedChannel, GuildTextBasedChannel, PermissionsBitField } from "d
import client from "../client"; import client from "../client";
export async function getGuildChannel(guildID: string, channelID: string): Promise<GuildBasedChannel | null> { export async function getGuildChannel(guildID: string, channelID: string): Promise<GuildBasedChannel | null> {
try {
const guild = await client.guilds.fetch(guildID); const guild = await client.guilds.fetch(guildID);
if (!guild) return null; if (!guild) return null;
const channel = await guild.channels.fetch(channelID); const channel = await guild.channels.fetch(channelID);
return channel; return channel;
} catch (_error) {
return null;
}
} }
export async function getChannelPermission(channel: GuildTextBasedChannel): Promise<Readonly<PermissionsBitField> | null> { export async function getChannelPermission(channel: GuildTextBasedChannel): Promise<Readonly<PermissionsBitField> | null> {