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] components: [actionRow]
}); });
await (BotClient.channels.cache.get(adminChannel!) as TextChannel).send({ adminChannel && await (BotClient.channels.cache.get(adminChannel!) as TextChannel).send({
embeds: [adminConfessionEmbed] embeds: [adminConfessionEmbed]
}); });

View file

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

View file

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

View file

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