Added purne subcommand to staff
This commit is contained in:
@@ -4,6 +4,7 @@ import { Command } from "interfaces"
|
|||||||
import help from "./staff/help"
|
import help from "./staff/help"
|
||||||
import beast from "./staff/beast"
|
import beast from "./staff/beast"
|
||||||
import updateDiscordRoles from "./staff/updatediscordroles"
|
import updateDiscordRoles from "./staff/updatediscordroles"
|
||||||
|
import prune from "./staff/prune"
|
||||||
|
|
||||||
export = {
|
export = {
|
||||||
name: "staff",
|
name: "staff",
|
||||||
@@ -31,6 +32,11 @@ export = {
|
|||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName("prune")
|
||||||
|
.setDescription("Update the discord roles of all guild members")
|
||||||
|
)
|
||||||
.addSubcommand(subcommand =>
|
.addSubcommand(subcommand =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("updatediscordroles")
|
.setName("updatediscordroles")
|
||||||
@@ -53,6 +59,11 @@ export = {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (subcommand === "prune") {
|
||||||
|
prune(interaction)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (subcommand === "updatediscordroles") {
|
if (subcommand === "updatediscordroles") {
|
||||||
updateDiscordRoles(interaction)
|
updateDiscordRoles(interaction)
|
||||||
return
|
return
|
||||||
|
|||||||
86
src/commands/staff/prune.ts
Normal file
86
src/commands/staff/prune.ts
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction, GuildMember } from "discord.js"
|
||||||
|
import { color, devMessage } from "config/options.json"
|
||||||
|
import env from "utils/Env"
|
||||||
|
|
||||||
|
export default async function prune(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||||
|
await interaction.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
|
if (interaction.user.id !== env.prod.dev) {
|
||||||
|
await interaction.editReply("You are not allowed to use this command.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const embedColor = Number(color.replace("#", "0x"))
|
||||||
|
const members = await interaction.guild!.members.fetch()
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [{
|
||||||
|
description: "Updating discord roles...",
|
||||||
|
color: embedColor
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
|
||||||
|
const fields: { name: string, value: string }[] = []
|
||||||
|
|
||||||
|
for (const member of members) {
|
||||||
|
const roles = member[1].roles.cache
|
||||||
|
|
||||||
|
if (roles.size !== 1) continue
|
||||||
|
|
||||||
|
const guildMember = await interaction.guild!.members.fetch(member[1].id)
|
||||||
|
|
||||||
|
fields.push({
|
||||||
|
name: guildMember.user.username,
|
||||||
|
value: guildMember.user.id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [{
|
||||||
|
title: "Prune",
|
||||||
|
description: "Prune members with no roles",
|
||||||
|
fields: fields.splice(0, 5),
|
||||||
|
color: embedColor,
|
||||||
|
thumbnail: {
|
||||||
|
url: interaction.guild!.iconURL() || ""
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
icon_url: interaction.guild!.iconURL() || undefined,
|
||||||
|
text: interaction.guild?.name + " | " + devMessage
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
components: [
|
||||||
|
new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setLabel("Confirm")
|
||||||
|
.setCustomId("staff_prune_confirm")
|
||||||
|
.setStyle(ButtonStyle.Danger)
|
||||||
|
.setEmoji("❗")
|
||||||
|
)
|
||||||
|
]
|
||||||
|
}).then(async () => {
|
||||||
|
const filter = (i: any) => i.customId === "staff_prune_confirm" && i.user.id === interaction.user.id
|
||||||
|
|
||||||
|
const collector = interaction.channel!.createMessageComponentCollector({ filter, time: 60000 })
|
||||||
|
|
||||||
|
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: []
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user