From 7f32b1e68096725a0a64b949e7c821bcf48c2c21 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 8 Feb 2024 18:07:52 +0100 Subject: [PATCH] Updated prune command --- src/commands/staff/prune.ts | 83 ++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/src/commands/staff/prune.ts b/src/commands/staff/prune.ts index b404031..359a2c5 100644 --- a/src/commands/staff/prune.ts +++ b/src/commands/staff/prune.ts @@ -3,7 +3,7 @@ import { embedColor, devMessage } from "config/options" import env from "utils/Env" export default async function prune(interaction: ChatInputCommandInteraction): Promise { - await interaction.deferReply({ ephemeral: true }) + await interaction.deferReply() if (interaction.user.id !== env.prod.dev) { await interaction.editReply("You are not allowed to use this command.") @@ -34,6 +34,10 @@ export default async function prune(interaction: ChatInputCommandInteraction): P }) } + const id = Math.random().toString(32).slice(2) + const buttonid = "button-" + id + const cancelid = "cancel-" + id + await interaction.editReply({ embeds: [{ title: "Prune", @@ -52,44 +56,65 @@ export default async function prune(interaction: ChatInputCommandInteraction): P new ActionRowBuilder().addComponents( new ButtonBuilder() .setLabel("Confirm") - .setCustomId("staff_prune_confirm") + .setCustomId(buttonid) .setStyle(ButtonStyle.Danger) - .setEmoji("❗") + .setEmoji("❗"), + new ButtonBuilder() + .setLabel("Cancel") + .setCustomId(cancelid) + .setStyle(ButtonStyle.Primary) + .setEmoji("❌") ) ] - }).then(async () => { - const filter = (i: ButtonInteraction) => i.customId === "staff_prune_confirm" && i.user.id === interaction.user.id - + }).then(async (m) => { const collector = interaction.channel!.createMessageComponentCollector({ componentType: ComponentType.Button, - filter: filter, + filter: (i: ButtonInteraction) => + (i.customId === buttonid || i.customId === cancelid) && + i.user.id === interaction.user.id, time: 5 * 60 * 1000 }) - collector.on("collect", async i => { - await i.deferUpdate() - - const members = i.message.embeds[0].fields - - for (const member of members) { - const guildMember = await interaction.guild!.members.fetch(member.value) - - await i.guild?.members.kick(guildMember, "Pruned") - } - - await i.editReply({ - embeds: [{ - description: "Prruned all the members", - color: embedColor - }], - components: [] - }).then(() => { - collector.stop() - }) - }) - collector.on("end", async () => { // ... }) + + collector.on("collect", async i => { + if (i.customId === cancelid) { + await m.edit({ + components: [] + }) + + await i.reply({ + embeds: [{ + description: "Cancelled", + color: embedColor + }], + }).then(() => { + collector.stop() + }) + return + } else if (i.customId === buttonid) { + await i.deferUpdate() + const members = i.message.embeds[0].fields + // for (const member of members) { + // const guildMember = await interaction.guild!.members.fetch(member.value) + // + // await i.guild?.members.kick(guildMember, "Pruned") + // } + + await m.edit({ + components: [], + }) + await i.editReply({ + embeds: [{ + description: "Pruned all the members", + color: embedColor + }], + }).then(() => { + collector.stop() + }) + } + }) }) }