Check for Logchannel permissions before accepting it
This commit is contained in:
parent
3a6641be86
commit
a8cd924e18
@ -1,8 +1,8 @@
|
|||||||
import { SlashCommandBuilder, PermissionFlagsBits, ChannelType, ChatInputCommandInteraction, NewsChannel, TextBasedChannel, CategoryChannel, StageChannel, TextChannel, PrivateThreadChannel, PublicThreadChannel, VoiceChannel, APIInteractionDataResolvedChannel, ForumChannel } from "discord.js";
|
import { SlashCommandBuilder, PermissionFlagsBits, ChannelType, ChatInputCommandInteraction, NewsChannel, TextBasedChannel, CategoryChannel, StageChannel, TextChannel, PrivateThreadChannel, PublicThreadChannel, VoiceChannel, APIInteractionDataResolvedChannel, ForumChannel } from "discord.js";
|
||||||
import getDefaultEmbed, { getSuccessEmbed } from "../tools/defaultEmbeds";
|
import getDefaultEmbed, { getFailedEmbed, getSuccessEmbed } from "../tools/defaultEmbeds";
|
||||||
import { database, GuildSetting } from "../data";
|
import { database, GuildSetting } from "../data";
|
||||||
import { getGuildSetting } from "../tools/data";
|
import { getGuildSetting } from "../tools/data";
|
||||||
import { getGuildChannel } from "../tools/discord";
|
import { getGuildChannel, getChannelPermission } from "../tools/discord";
|
||||||
import { Emoji } from "../tools/design";
|
import { Emoji } from "../tools/design";
|
||||||
|
|
||||||
const builder = new SlashCommandBuilder();
|
const builder = new SlashCommandBuilder();
|
||||||
@ -55,6 +55,20 @@ const execute = async (interaction: ChatInputCommandInteraction) => {
|
|||||||
if (!optionVal) return await resetNotificationChannel(guildSetting, interaction);
|
if (!optionVal) return await resetNotificationChannel(guildSetting, interaction);
|
||||||
|
|
||||||
const channel = getTextBasedChannel(optionVal);
|
const channel = getTextBasedChannel(optionVal);
|
||||||
|
if (channel.isDMBased()) return;
|
||||||
|
|
||||||
|
const permissions = await getChannelPermission(channel);
|
||||||
|
if (!permissions || !permissions.has(PermissionFlagsBits.ViewChannel) || !permissions.has(PermissionFlagsBits.SendMessages)) {
|
||||||
|
const embed = getFailedEmbed();
|
||||||
|
embed.setDescription(`Bot doesn't have permission to view and/or write in channel <#${channel.id}>`);
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [ embed ],
|
||||||
|
ephemeral: true
|
||||||
|
}).catch();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (guildSetting.notificationChannelID) {
|
if (guildSetting.notificationChannelID) {
|
||||||
const oldLogChannel = await getGuildChannel(guildSetting.id, guildSetting.notificationChannelID);
|
const oldLogChannel = await getGuildChannel(guildSetting.id, guildSetting.notificationChannelID);
|
||||||
const embed = getDefaultEmbed();
|
const embed = getDefaultEmbed();
|
||||||
|
Loading…
Reference in New Issue
Block a user