Files
FWS-DiscordBot/src/commands/moderation/clear.js
T

50 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
import { ACCESS_LEVELS } from '../../config/constants.js';
import { UserFacingError } from '../../core/errors.js';
import { logModerationAction } from '../../services/moderation/moderation-service.js';
import { successEmbed } from '../../ui/embeds.js';
export const access = ACCESS_LEVELS.STAFF;
export const data = new SlashCommandBuilder()
.setName('clear')
.setDescription('Supprimer des messages')
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
.addIntegerOption((option) =>
option
.setName('amount')
.setDescription('Nombre de messages à supprimer (1 à 100)')
.setRequired(true)
.setMinValue(1)
.setMaxValue(100),
);
/** Bulk deletes messages in the current channel and logs it (M8-T05). */
export async function execute(interaction) {
const amount = interaction.options.getInteger('amount', true);
if (!interaction.channel?.isTextBased() || !interaction.channel.bulkDelete) {
throw new UserFacingError(
'Je ne peux pas supprimer plusieurs messages d’un coup ici : lance la commande dans un salon textuel.',
);
}
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
const deleted = await interaction.channel.bulkDelete(amount, true);
await logModerationAction(interaction, {
action: 'clear',
targetId: null,
reason: `${deleted.size} message(s) supprimé(s) dans #${interaction.channel.name}`,
});
await interaction.editReply({
embeds: [
successEmbed(
`C’est nettoyé : ${deleted.size} message(s) supprimé(s) dans <#${interaction.channelId}>.` +
(deleted.size < amount
? '\n_Discord conserve les messages de plus de 14 jours : ils n’ont pas pu être retirés._'
: ''),
),
],
});
}