From e57545eaaf49514ff756ac25bfb857b6d7949890 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 8 Feb 2024 17:34:38 +0100 Subject: [PATCH 1/3] Updated prune command --- src/commands/staff/prune.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/commands/staff/prune.ts b/src/commands/staff/prune.ts index bfde038..b404031 100644 --- a/src/commands/staff/prune.ts +++ b/src/commands/staff/prune.ts @@ -1,4 +1,4 @@ -import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction } from "discord.js" +import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ChatInputCommandInteraction, ComponentType } from "discord.js" import { embedColor, devMessage } from "config/options" import env from "utils/Env" @@ -58,9 +58,13 @@ export default async function prune(interaction: ChatInputCommandInteraction): P ) ] }).then(async () => { - const filter = (i: any) => i.customId === "staff_prune_confirm" && i.user.id === interaction.user.id + const filter = (i: ButtonInteraction) => i.customId === "staff_prune_confirm" && i.user.id === interaction.user.id - const collector = interaction.channel!.createMessageComponentCollector({ filter, time: 60000 }) + const collector = interaction.channel!.createMessageComponentCollector({ + componentType: ComponentType.Button, + filter: filter, + time: 5 * 60 * 1000 + }) collector.on("collect", async i => { await i.deferUpdate() @@ -79,7 +83,13 @@ export default async function prune(interaction: ChatInputCommandInteraction): P color: embedColor }], components: [] + }).then(() => { + collector.stop() }) }) + + collector.on("end", async () => { + // ... + }) }) } From 7f32b1e68096725a0a64b949e7c821bcf48c2c21 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 8 Feb 2024 18:07:52 +0100 Subject: [PATCH 2/3] 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() + }) + } + }) }) } From 195375631e3a54c9bb241bb09e67e47e6a48e7a3 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 8 Feb 2024 18:08:27 +0100 Subject: [PATCH 3/3] Smh forgot to uncomment main part --- src/commands/staff/prune.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/commands/staff/prune.ts b/src/commands/staff/prune.ts index 359a2c5..894f57f 100644 --- a/src/commands/staff/prune.ts +++ b/src/commands/staff/prune.ts @@ -97,11 +97,11 @@ export default async function prune(interaction: ChatInputCommandInteraction): P } 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") - // } + 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: [],