title: How do I delete only 10 messages if the user provided 20 messages (older than 14 days) for bulk deleting in discord.js
body: <p>I'm new in Discord.js I've recently made a &quot;purge&quot; command and it looks like this-</p>
  <pre class="lang-js prettyprint-override"><code>if (message.content.toLowerCase().startsWith(prefix + &quot;purge&quot;) || message.content.toLowerCase().startsWith(prefix + &quot;clear&quot;)) {
      const args = message.content.split(' ').slice(1); // All arguments behind the command name with the prefix
      const amount = args.join(' '); // Amount of messages which should be deleted
      if (message.channel.type === &quot;DM&quot;) return message.reply('Cannot run command inside DMs.')
      if (!message.member.hasPermission('MANAGE_MESSAGES') || !message.member.hasPermission('ADMINISTRATOR')) return message.channel.reply('You do not have enough permissions to run this command')
      if (!message.guild.me.hasPermission('MANAGE_MESSAGES') || !message.guild.me.hasPermission('ADMINISTRATOR')) return message.reply('I do not have permission to delete messages.')
      if (!amount) return message.reply('You haven\'t given an amount of messages which should be deleted!'); // Checks if the `amount` parameter is given
      if (isNaN(amount)) return message.reply('The amount parameter isn`t a number!'); // Checks if the `amount` parameter is a number. If not, the command throws an error
      if (amount &gt; 99) return message.reply('You can`t delete more than 99 messages at once!'); // Checks if the `amount` integer is bigger than 100
      if (amount &lt; 1) return message.reply('You have to delete at least 1 message!'); // Checks if the `amount` integer is smaller than 1
      message.channel.messages.fetch({
          limit: amount
      }).then(messages =&gt; { // Fetches the messages
          message.channel.bulkDelete(messages) // Bulk deletes all messages that have been fetched and are not older than 14 days (due to the Discord API)
          message.channel.send(`Deleted ${amount} messages. Messages purged by ${message.author.username}`)
      });
  }
  }
  </code></pre>
  <p>So the thing is, when I tested my bot in an old server with older messages, there was 23 new messages and 44 old messages. I tried to delete 50 messages. All it did was log the error in the console and send a message that 50 messages was deleted. It didn't really delete 50 messages but it sent a message it did delete. Is it possible to delete only the maximum number of messages that can be deleted and then send a message of how many messages are actually deleted, it'll be helpful. I'll tell an example- I want to delete 50 messages but 10 are under 14 days and the rest are over 14 days. The bot will delete 10 messages (the maximum it can delete just like Carl bot does.)</p>