You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
895 B

5 years ago
  1. module.exports = {
  2. name: 'purge',
  3. roles: ['732345527143759943'],
  4. description: 'Purge the last few messages specified by the user!',
  5. async execute(message,args) {
  6. let fetched;
  7. let amount = Number(message.content.split(" ")[1]);
  8. if(!amount){
  9. return message.channel.send("You must specify an amount to purge");
  10. }
  11. let deleted = 0;
  12. let channel = message.channel;
  13. let message_manager = channel.messages;
  14. do {
  15. let limit = 100;
  16. if(amount - deleted < limit){
  17. limit = amount - deleted;
  18. }
  19. fetched = await message_manager.fetch({ limit: limit });
  20. channel.bulkDelete(fetched);
  21. deleted += fetched.size
  22. }
  23. while(fetched.size >= 3 && deleted < amount);
  24. let m = await message.channel.send("Done purging!")
  25. }
  26. }