Warn if logchannel is misconfigured

This commit is contained in:
Lukas | AstroGD 2022-11-29 00:22:50 +01:00
parent a8cd924e18
commit f7c878854b
Signed by: AstroGD
GPG Key ID: 82A5E6C236C535AA

View File

@ -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<void>
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<void>
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();
}