Add channel permission getter

This commit is contained in:
Lukas | AstroGD 2022-11-29 00:05:04 +01:00
parent 730151e34b
commit 0d69cf3e7b
Signed by: AstroGD
GPG Key ID: 82A5E6C236C535AA

View File

@ -1,4 +1,4 @@
import { GuildBasedChannel } from "discord.js";
import { GuildBasedChannel, GuildTextBasedChannel, PermissionsBitField } from "discord.js";
import client from "../client";
export async function getGuildChannel(guildID: string, channelID: string): Promise<GuildBasedChannel | null> {
@ -7,4 +7,15 @@ export async function getGuildChannel(guildID: string, channelID: string): Promi
const channel = await guild.channels.fetch(channelID);
return channel;
}
export async function getChannelPermission(channel: GuildTextBasedChannel): Promise<Readonly<PermissionsBitField> | null> {
try {
const guildMember = await channel.guild.members.fetch(client.user!.id);
if (!guildMember) return null;
return channel.permissionsFor(guildMember);
} catch (error) {
return null;
}
}