2023-05-23 01:14:17 -04:00
|
|
|
import Discord from 'discord.js';
|
2023-04-14 06:47:58 -04:00
|
|
|
import TClient from '../client.js';
|
2023-10-06 01:54:27 -04:00
|
|
|
import MessageTool from '../helpers/MessageTool.js';
|
2023-12-24 10:21:40 -05:00
|
|
|
export default class Purge {
|
|
|
|
static async run(_client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
|
|
|
|
if (!MessageTool.isStaff(interaction.member)) return MessageTool.youNeedRole(interaction, 'dcmod');
|
2023-03-05 05:04:10 -05:00
|
|
|
const amount = interaction.options.getInteger('amount') as number;
|
|
|
|
if (amount > 100) return interaction.reply({content: 'Discord API limits purging up to 100 messages.', ephemeral: true})
|
|
|
|
const user = interaction.options.getUser('user');
|
|
|
|
let messagesArray: Array<string> = [];
|
2022-11-18 06:29:03 -05:00
|
|
|
|
2023-03-05 05:04:10 -05:00
|
|
|
if (user){
|
|
|
|
(interaction.channel as Discord.TextChannel).messages.fetch({limit: amount}).then(msgs=>{
|
2023-07-07 09:49:24 -04:00
|
|
|
const msgList = msgs.filter(x=>x.author.id === user.id);
|
2023-03-05 05:04:10 -05:00
|
|
|
(interaction.channel as Discord.TextChannel).bulkDelete(msgList);
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
(interaction.channel as Discord.TextChannel).messages.fetch({limit: amount}).then(async messages=>{
|
|
|
|
messages.forEach(message=>messagesArray.push(message.id));
|
|
|
|
await (interaction.channel as Discord.TextChannel).bulkDelete(messagesArray);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
await interaction.reply({content: `Successfully purged ${amount} messages.`, ephemeral: true})
|
2023-12-24 10:21:40 -05:00
|
|
|
}
|
|
|
|
static data = new Discord.SlashCommandBuilder()
|
2023-03-05 05:04:10 -05:00
|
|
|
.setName('purge')
|
|
|
|
.setDescription('Purge the amount of messages in this channel')
|
2023-05-23 01:14:17 -04:00
|
|
|
.addIntegerOption(x=>x
|
2023-03-05 05:04:10 -05:00
|
|
|
.setName('amount')
|
|
|
|
.setDescription('Amount of messages to be obliterated')
|
|
|
|
.setRequired(true))
|
2023-05-23 01:14:17 -04:00
|
|
|
.addUserOption(x=>x
|
2023-03-05 05:04:10 -05:00
|
|
|
.setName('user')
|
|
|
|
.setDescription('Which user to have their messages obliterated?'))
|
2023-10-06 01:54:27 -04:00
|
|
|
}
|