April/commands/moderation/clear.js
2023-08-29 22:40:42 +02:00

30 lines
955 B
JavaScript

const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('clear')
.setDefaultMemberPermissions(0x2)
.addIntegerOption(
option =>
option
.setName('nombre')
.setDescription('Quantité de messages à supprimer')
.setMinValue(1)
.setMaxValue(100)
.setRequired(true)
)
.setDescription('Supprimer un grand nombre de messages d\'un salon'),
async execute(interaction, client) {
const number = interaction.options.getInteger('nombre');
try {
const fetched = await interaction.channel.fetchMessages({ limit: number });
const notPinned = fetched.filter(fetchedMsg => !fetchedMsg.pinned);
await interaction.channel.bulkDelete(notPinned, true);
await interaction.reply({ content: `J'ai bien supprimé ${number} message${number>1 ? "s" : ""} dans ce salon`, ephemeral: true});
} catch(err) {
console.error(err);
}
}
};