From 1348db4eb30b8b98983ebf65258c4ef6d5bcc53b Mon Sep 17 00:00:00 2001 From: Ninjdai <65647523+Ninjdai1@users.noreply.github.com> Date: Tue, 29 Aug 2023 22:40:42 +0200 Subject: [PATCH] /clear no longer deletes pinned messages --- commands/moderation/clear.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/commands/moderation/clear.js b/commands/moderation/clear.js index cd74594..464d5b4 100644 --- a/commands/moderation/clear.js +++ b/commands/moderation/clear.js @@ -15,8 +15,15 @@ module.exports = { ) .setDescription('Supprimer un grand nombre de messages d\'un salon'), async execute(interaction, client) { - const number = interaction.options.getInteger('nombre'); - await interaction.channel.bulkDelete(number); - await interaction.reply({ content: `J'ai bien supprimé ${number} message${number>1 ? "s" : ""} dans ce salon`, ephemeral: true}); + 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); + } } -}; \ No newline at end of file +};