Advertisement
YoJxsn

Untitled

Nov 5th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. const BaseCommand = require('../../utils/structures/BaseCommand');
  2. const Discord = require ('discord.js');
  3. module.exports = class PurgeCommand extends BaseCommand {
  4. constructor() {
  5. super('purge', 'Moderation', []);
  6. }
  7.  
  8. async run(client, message, args) {
  9. if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send('You cannot use this command.');
  10. if (!message.guild.me.hasPermission("MANAGE_MESSAGES")) return message.channel.send("I don't have \`MANAGE_MESSAGES\` permission.")
  11. if (!args[0]) return message.channel.send("You must state a number of messages to purge. \`+purge number\`")
  12. const amountToDelete = Number(args[0], 10);
  13. if (isNaN(amountToDelete)) return message.channel.send("Number stated is not a valid number.")
  14. if (!Number.isInteger(amountToDelete)) return message.channel.send("Number stated must be a whole number.");
  15. if (!amountToDelete || amountToDelete < 2 || amountToDelete > 100) return message.channel.send('The number stated must be between 2 and 100.');
  16. const fetched = await message.channel.messages.fetch({
  17. limit: amountToDelete
  18. });
  19.  
  20. try {
  21. await message.channel.bulkDelete(fetched);
  22. .then(messages => message.channel.send(`Deleted ${messages.size} messages!`));
  23.  
  24. } catch (err) {
  25. console.log(err);
  26. message.channel.send(`I was unable to delete the amount stated make sure they are within 14 days old.`)
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement