diff options
| author | 8cy <[email protected]> | 2020-04-10 10:16:53 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-04-10 10:16:53 -0700 |
| commit | 4b308538961facb87d73fafeab7fab5927562eff (patch) | |
| tree | 8eaf88c074c379d76e7932e6fc3f32c05adb70ca /commands/utility/clear.js | |
| parent | rework reboot, work on itemshop, v1.5.2 (diff) | |
| download | s5nical-4b308538961facb87d73fafeab7fab5927562eff.tar.xz s5nical-4b308538961facb87d73fafeab7fab5927562eff.zip | |
port to commando/ v12, 2.0.0
ported everything over to v12 and then commando in the span of 2 days no sleep lol. also now using typescript standard for cool 8)
Diffstat (limited to 'commands/utility/clear.js')
| -rw-r--r-- | commands/utility/clear.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/commands/utility/clear.js b/commands/utility/clear.js new file mode 100644 index 0000000..61f9fbb --- /dev/null +++ b/commands/utility/clear.js @@ -0,0 +1,62 @@ +const { Command } = require('discord.js-commando'); + +module.exports = class ClearUtility extends Command { + constructor(client) { + super(client, { + name: 'clear', + aliases: ['delete', 'del', 'c'], + group: 'utility', + memberName: 'clear', + description: 'clear an ammount of messages', + guildOnly: true, + args: [ + { + key: 'deleteAmount', + prompt: 'how many messages would u like to delete?', + type: 'integer' + } + ] + }); + } + async run(msg, { deleteAmount }) { + if (msg.member.hasPermission('MANAGE_MESSAGES')) { + if (!deleteAmount) { + msg.reply('you haven\'t specified an amount of messages which should be deleted.').then(deleteNotificationMessage => { + deleteNotificationMessage.delete({ timeout: 1000 }); + }); + } else if (isNaN(deleteAmount)) { + msg.reply('the amount parameter isn\'t a number.').then(deleteNotificationMessage => { + deleteNotificationMessage.delete({ timeout: 1000 }); + }); + } else if (deleteAmount > 100) { + msg.reply('you can\'t delete more than 100 messages at once.').then(deleteNotificationMessage => { + deleteNotificationMessage.delete({ timeout: 1000 }); + }); + } else if (deleteAmount < 1) { + msg.reply('you have to delete at least 1 message.').then(deleteNotificationMessage => { + deleteNotificationMessage.delete({ timeout: 1000 }); + }); + } + /*else if (msg.createdTimestamp > 1209600) { + msg.reply('due to discord rules, bots can only bulk delete messages that are under 14 days old :(') + } */ + else { + var clearAmount = deleteAmount + 1; + // It took me so long to figure out why this was not really working. It would delete but an insane amount at a time. + // I realized that because it was getting parsed as a string, it would just add 1 to it so if I tried to delete 1 + // message, it would delete 11 lol. Fixed by parsing as integer THEN adding one. 02:30 2020/04/03/2020 + + await msg.channel.messages.fetch({ + limit: clearAmount + }).then(messages => { // I am on v11 discord.js + msg.channel.bulkDelete(messages); + }); + msg.reply('it\'s been deleted ~uwu').then(deleteNotificationMessage => { + deleteNotificationMessage.delete({ timeout: 1000 }); + }); + } + } else { + msg.reply('insufficent perms bruh'); + } + } +};
\ No newline at end of file |