This repository has been archived by the owner on Apr 26, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
purge.js
67 lines (62 loc) · 1.99 KB
/
purge.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const { Command } = require('discord-akairo');
class Purge extends Command {
constructor() {
super('purge', {
aliases: ['purge', 'prune'],
channel: 'guild',
category: 'Guild Management',
description: {
content:
'Deletes number of messages as per the arguments entered by the command executor.',
usage: '<number>',
examples: ['15'],
},
cooldown: 5000,
userPermissions: ['MANAGE_MESSAGES'],
clientPermissions: ['MANAGE_MESSAGES'],
args: [
{
id: 'count',
type: (__, phrase) => {
if (!phrase || isNaN(parseInt(phrase))) return null;
const num = parseInt(phrase);
if (num < 2 || num > 100) return null;
return num;
},
prompt: {
start: (msg) =>
`<a:RedTick:760514410115498025> ${msg.author}, how many messages do you want to clean ? (2-100)`,
retry: (msg) =>
`<a:RedTick:760514410115498025> ${msg.author}, please enter a number between 2 and 100!`,
},
},
],
});
}
async exec(message, { count }) {
message.delete();
const messages = await message.channel.messages.fetch();
const filtered = messages
.filter((msg) => msg.id !== message.id)
.sort((a, b) => b.createdTimestamp - a.createdTimestamp)
.array()
.slice(0, count);
message.channel
.send(`Deleting ${filtered.length} messages, please wait...`)
.then((msg) => {
message.channel.bulkDelete(filtered, true).then(({ size }) => {
msg
.edit(
`<:check:753484699237613630> **${size}** messages has been successfully purged by **${message.author.tag}**.`
)
.then((mssg) => {
mssg.delete({ timeout: 5000 });
});
});
})
.catch((err) => {
message.util.send(`<a:RedTick:760514410115498025> **${err}**`);
});
}
}
module.exports = Purge;