-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (39 loc) · 1.35 KB
/
index.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
const { readdir } = require("fs");
const { Client } = require('discord.js');
const client = new Client({});
try {
client.config = require('./config/config.json');
} catch (e) {
console.log("Config file not found. Please create a config.json file in the config folder.".red);
process.exit(1);
}
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
console.log(err.stack);
});
client.on('ready', () => {
console.log("\nBot Started!\n".rainbow.bold);
let guildChannel = client.guilds.cache.get(client.config.guild).channels.cache.get(client.config.channel)
setInterval(async () => {
let messageDeleteQueue = [];
let lastMessageId = null;
while (true) {
let messages = await guildChannel.messages.fetch({
limit: 100,
before: lastMessageId
});
if (messages.size === 0) {
break;
}
lastMessageId = messages.last().id;
messages.forEach(message => {
if (message.createdTimestamp < Date.now() - 1000 * 60 * 60 * 24 * 7) messageDeleteQueue.push(message.id);
})
}
await guildChannel.bulkDelete(messageDeleteQueue, true);
}, 1000 * 60 * 60);
});
client.login(client.config.token);