Closed matiasdelbulla closed 2 years ago
Fairly simple addition to add. I'd check the discord.js docs or guide for more but since I had it on hand here's what I think you're looking for
module.exports = {
name: "purge",
description: "Bulk prune / purge messages",
role: "mod",
options: [
{
name: "amount",
type: "NUMBER",
required: true,
description: "Number of messages to purge",
},
],
run: async (client, interaction, args) => {
if (args.amount > 100 || args.amount < 2) return interaction.reply({ content: "You can only delete between 2 and 100 messages at a time", ephermeral: true });
await interaction.channel.messages.fetch({ limit: args.amount }).catch();
await interaction.channel.bulkDelete(args.amount, true).catch(console.error);
return interaction.reply({ content: `Deleted ${args.amount} messages.`, ephemeral: true });
},
};
Note: it's set to mod role here and there's a limit to 100 messages max from the discord api.
*Also you can probably safely remove await interaction.channel.messages.fetch({ limit: args.amount }).catch();
I only do it cause I my bot logs deleted messages and it can't if they're not cached with discord.js so it fetches them beforehand.
I assume from your silence this worked for you? closing.
I think this bot is very good, I have been modifying it so that the commands work with my server (ESX LEGACY), but I would like to know if I could add a purge text command, thus avoiding using another bot in my discord, something like /purge NUMBER, and to delete the messages indicated in the number