diff --git a/src/commands/showSettings.ts b/src/commands/showSettings.ts index 2455fb3..dc003f9 100644 --- a/src/commands/showSettings.ts +++ b/src/commands/showSettings.ts @@ -4,7 +4,7 @@ import { getGuildSetting, isPremiumActive } from "../tools/data"; import getDefaultEmbed from "../tools/defaultEmbeds"; import moment from "moment"; import { Color, Emoji } from "../tools/design"; -import { getGuildChannel } from "../tools/discord"; +import { getGuildChannel, getChannelPermission } from "../tools/discord"; const builder = new SlashCommandBuilder(); builder.setName("showsettings"); @@ -35,7 +35,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise inline: true }, { name: "Logchannel", - value: logChannel && logChannel.isTextBased() ? `<#${logChannel.id}>` : "Not configured", + value: settings.notificationChannelID ? `<#${settings.notificationChannelID}>` : "Not configured", inline: true }, { name: "Words in Blocklist", @@ -49,8 +49,27 @@ async function execute(interaction: ChatInputCommandInteraction): Promise value: "Join the support server at https://go.astrogd.eu/discord" }); + const embeds = []; + embeds.push(embed); + + const invalidLogChannelEmbed = getDefaultEmbed(); + invalidLogChannelEmbed.setColor(Color.WARNING_YELLOW); + invalidLogChannelEmbed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Logchannel is misconfigured!`); + invalidLogChannelEmbed.setDescription("The bot is unable to read and/or write in the configured logChannel. Please adjust your permissions."); + + if (logChannel && logChannel.isTextBased()) { + const permissions = await getChannelPermission(logChannel); + if (!permissions || !permissions.has(PermissionFlagsBits.ViewChannel) || !permissions.has(PermissionFlagsBits.SendMessages)) { + embeds.push(invalidLogChannelEmbed); + } + } + + if ((!logChannel || !logChannel.isTextBased()) && settings.notificationChannelID) { + embeds.push(invalidLogChannelEmbed); + } + interaction.reply({ - embeds: [embed], + embeds: embeds, ephemeral: true }).catch(); }