-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
88 lines (77 loc) · 2.98 KB
/
index.js
File metadata and controls
88 lines (77 loc) · 2.98 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// using discord js v14! most current tutorials are v13 so be wary
require('dotenv').config();
const { updateClanData } = require('./functions.js');
const fs = require('node:fs');
const path = require('node:path');
const TOKEN = process.env.DISC_TOKEN;
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildModeration,
],
});
// command handling stuff
client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
}
// button handling stuff
client.buttons = new Collection();
const buttonsPath = path.join(__dirname, 'buttons');
const buttonFiles = fs.readdirSync(buttonsPath).filter(file => file.endsWith('.js'));
for (const file of buttonFiles) {
const filePath = path.join(buttonsPath, file);
const button = require(filePath);
client.buttons.set(button.data.name, button);
}
// modal handling stuff
client.modals = new Collection();
const modalsPath = path.join(__dirname, 'modals');
const modalFiles = fs.readdirSync(modalsPath).filter(file => file.endsWith('.js'));
for (const file of modalFiles) {
const filePath = path.join(modalsPath, file);
const modal = require(filePath);
client.modals.set(modal.data.name, modal);
}
// event handling stuff
const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute (...args));
}
else {
client.on(event.name, (...args) => event.execute(...args));
}
}
// discord api error handling
process.on('unhandledRejection', async (err) => {
console.error('Unhandled Promise Rejection:\n', err);
});
process.on('uncaughtException', async (err) => {
console.error('Uncaught Promise Exception:\n', err);
});
process.on('uncaughtExceptionMonitor', async (err) => {
console.error('Uncaught Promise Exception (Monitor):\n', err);
});
// process.on('multipleResolves', async (type, promise, reason) => {
// console.error('Multiple Resolves:\n', type, promise, reason);
// });
// login/start bot
client.login(TOKEN)
.then(result => {
setInterval(() => updateClanData(682808, client, '1249901127940440156'), 900000); // clan logs are checked every 15 minutes
updateClanData(682808, client, '1249901127940440156');
})