summaryrefslogtreecommitdiff
path: root/commands/clear.js
blob: fe8e46fbb92b896d38ec5bc05099be772e91b8b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module.exports = {
    name: 'clear',
    aliases: ['delete', 'del', 'c'],
    description: '',
    async execute(msg, args, bot) {
        if (msg.member.hasPermission('MANAGE_MESSAGES')) {
            if (!args) {
                msg.reply('you haven\'t specified an amount of messages which should be deleted.').then(deleteNotificationMessage => {
                    deleteNotificationMessage.delete(1000);
                });
            } else if (isNaN(args)) {
                msg.reply('the amount parameter isn\'t a number.').then(deleteNotificationMessage => {
                    deleteNotificationMessage.delete(1000);
                });
            } else if (args > 100) {
                msg.reply('you can\'t delete more than 100 messages at once.').then(deleteNotificationMessage => {
                    deleteNotificationMessage.delete(1000);
                });
            } else if (args < 1) {
                msg.reply('you have to delete at least 1 message.').then(deleteNotificationMessage => {
                    deleteNotificationMessage.delete(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 = parseInt(args[0]) + 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.fetchMessages({
                    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(1000);
                });
            }
        } else {
            msg.reply('insufficent perms bruh');
        }
    }
};