Make logging channel optional

This commit is contained in:
powermaker450 2024-10-17 19:15:52 -04:00
parent ae27c7d24e
commit df09fe8787
4 changed files with 44 additions and 9 deletions

View file

@ -153,7 +153,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
components: [actionRow]
});
await (BotClient.channels.cache.get(adminChannel!) as TextChannel).send({
adminChannel && await (BotClient.channels.cache.get(adminChannel!) as TextChannel).send({
embeds: [adminConfessionEmbed]
});

View file

@ -18,6 +18,8 @@
import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
ChannelSelectMenuBuilder,
ChannelType,
CommandInteraction,
@ -51,9 +53,17 @@ export async function execute(interaction: CommandInteraction) {
.setCustomId("channels")
.setPlaceholder("Choose a channel");
const skipButton = new ButtonBuilder()
.setCustomId("skipModChannel")
.setLabel("Skip")
.setStyle(ButtonStyle.Secondary)
const channelRow =
new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents(channelList);
const buttonRow = new ActionRowBuilder<ButtonBuilder>()
.addComponents(skipButton);
try {
const response = await interaction.reply({
content: `# Let's get started, ${interaction.user.displayName}!\nFirst, let's choose a channel for your confessions.`,
@ -67,7 +77,7 @@ export async function execute(interaction: CommandInteraction) {
});
collector.on("collect", async i => {
confessChannel = i.values[0];
[ confessChannel ] = i.values;
await i.update({
content: "Awesome!",
@ -89,7 +99,7 @@ export async function execute(interaction: CommandInteraction) {
const logResponse = await interaction.followUp({
content: "# Now, select a logging channel, for moderation purposes.",
ephemeral: true,
components: [logChannelRow]
components: [logChannelRow, buttonRow]
});
const logCollector = logResponse.createMessageComponentCollector({
@ -97,8 +107,15 @@ export async function execute(interaction: CommandInteraction) {
time: 45_000
});
const skipCollector = logResponse.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 45_000
});
let skipped = false;
logCollector.on("collect", async ij => {
logChannel = ij.values[0];
[ logChannel ] = ij.values;
await ij.update({
content: "Setup Complete!",
@ -112,11 +129,30 @@ export async function execute(interaction: CommandInteraction) {
});
logCollector.stop();
skipCollector.stop();
});
skipCollector.on("collect", async ik => {
if (ik.customId === "skipModChannel") {
await ik.update({
content: "Setup complete!",
components: []
});
dt.setup(guildId!, {
confessChannel: confessChannel,
bans: []
});
skipped = true;
logCollector.stop();
skipCollector.stop();
}
})
logCollector.on("end", content => {
// If there is no content, follow up with an error message.
!content.size &&
// If there is no content and the channel hasn't been skipped, follow up with an error message.
(!content.size && !skipped) &&
interaction.followUp({
content: "No channel selected. Please try again.",
ephemeral: true,

View file

@ -21,7 +21,6 @@ import {
ButtonBuilder,
ButtonStyle,
ChatInputCommandInteraction,
ComponentType,
EmbedBuilder,
Events,
TextChannel
@ -180,7 +179,7 @@ BotClient.on(Events.InteractionCreate, async interaction => {
components: [actionRow]
});
await (BotClient.channels.cache.get(adminChannel!) as TextChannel).send({
adminChannel && await (BotClient.channels.cache.get(adminChannel!) as TextChannel).send({
embeds: [adminConfessionEmbed]
});

View file

@ -32,7 +32,7 @@ export interface ConfessionBan {
export interface GuildSettings {
confessChannel: string;
modChannel: string;
modChannel?: string;
bans: ConfessionBan[];
}