import { SlashCommandBuilder } from "discord.js";

const command = {
  data: new SlashCommandBuilder()
    .setName("deletemsgs")
    .setDescription("Supprime tous les messages, sauf ceux épinglés"),
  async execute(interaction) {
    let textChannel = interaction.client.channels.cache.get(
      interaction.channelId
    );

    textChannel.messages
      .fetch({ limit: 100 })
      .then((fetched) => {
        const notPinned = fetched.filter((fetchedMsg) => !fetchedMsg.pinned);
        textChannel.bulkDelete(notPinned, true);
        console.log(
          `[${new Date().toLocaleString()}] Command : Delete Messages used`
        );
      })
      .catch(console.error);

    interaction.reply("Et voila, c'est tout propre ! 🐱").then(() => {
      setTimeout(() => {
        interaction.deleteReply();
      }, 7000);
    });
  },
};

export { command };
