title: Discord.js v12 clear command
body: <p>I have a <code>clear</code> command which deletes the amount of messages you would like to. But whenever I say <code>clear 3</code>, it'll clear only 2 messages instead.</p>
  <pre class="lang-js prettyprint-override"><code>client.on('message', async (message) =&gt; {
    if (
      message.content.toLowerCase().startsWith(prefix + 'clear') ||
      message.content.toLowerCase().startsWith(prefix + 'c ')
    ) {
      if (!message.member.hasPermission('MANAGE_MESSAGES'))
        return message.channel.send(&quot;You cant use this command since you're missing `manage_messages` perm&quot;);
      if (!isNaN(message.content.split(' ')[1])) {
        let amount = 0;
        if (message.content.split(' ')[1] === '1' || message.content.split(' ')[1] === '0') {
          amount = 1;
        } else {
          amount = message.content.split(' ')[1];
          if (amount &gt; 100) {
            amount = 100;
          }
        }
        await message.channel.bulkDelete(amount, true).then((_message) =&gt; {
          message.channel.send(`Bot cleared \`${_message.size}\` messages :broom:`).then((sent) =&gt; {
            setTimeout(function () {
              sent.delete();
            }, 2500);
          });
        });
      } else {
        message.channel.send('enter the amount of messages that you would like to clear').then((sent) =&gt; {
          setTimeout(function () {
            sent.delete();
          }, 2500);
        });
      }
    } else {
      if (message.content.toLowerCase() === prefix + 'help clear') {
        const newEmbed = new Discord.MessageEmbed().setColor('#00B2B2').setTitle('**Clear Help**');
        newEmbed
          .setDescription('This command clears messages for example `.clear 5` or `.c 5`.')
          .setFooter(`Requested by ${message.author.tag}`, message.author.displayAvatarURL())
          .setTimestamp();
        message.channel.send(newEmbed);
      }
    }
  });
  </code></pre>