-
Notifications
You must be signed in to change notification settings - Fork 58
/
index.js
70 lines (61 loc) · 2.43 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
Author: iTz Arshia
Github: https://github.com/iTzArshia/GPT-Discord-Bot
Current Version: 2.0.2
DiscordJs Version: 14.8.0
OpenAI Version: 3.2.1
*/
const Discord = require('discord.js');
const chalk = require('chalk');
const fs = require('node:fs');
const config = require('./configs/config.json');
// Discord Client Constructor
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.MessageContent
]
});
// Event Handler
console.log(chalk.bold.yellowBright('Loading Events'));
const events = fs.readdirSync(`./events/`).filter(file => file.endsWith('.js'));
for (const file of events) {
const event = require(`./events/${file}`);
client.on(file.split('.')[0], event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
};
// Message Command Handler
console.log(chalk.bold.yellowBright('Loading Message Commands'));
client.MessageCommands = new Discord.Collection();
const messageCommands = fs.readdirSync(`./commands/messages/`).filter(files => files.endsWith('.js'));
for (const file of messageCommands) {
const command = require(`./commands/messages/${file}`);
client.MessageCommands.set(command.name.toLowerCase(), command);
delete require.cache[require.resolve(`./commands/messages/${file}`)];
};
// Slash Command Handler
console.log(chalk.bold.yellowBright('Loading Slash Commands'));
client.SlashCommands = new Discord.Collection();
const slashCommands = fs.readdirSync(`./commands/interactions/`).filter(files => files.endsWith('.js'));
for (const file of slashCommands) {
const command = require(`./commands/interactions/${file}`);
client.SlashCommands.set(command.data.name, command);
delete require.cache[require.resolve(`./commands/interactions/${file}`)];
};
// Anti Crash
process.on('unhandledRejection', (reason, p) => {
console.log(chalk.bold.redBright('[antiCrash] :: Unhandled Rejection/Catch'));
console.log(reason?.stack, p);
});
process.on("uncaughtException", (err, origin) => {
console.log(chalk.bold.redBright('[antiCrash] :: ncaught Exception/Catch'));
console.log(err?.stack, origin);
});
process.on('uncaughtExceptionMonitor', (err, origin) => {
console.log(chalk.bold.redBright('[antiCrash] :: Uncaught Exception/Catch (MONITOR)'));
console.log(err?.stack, origin);
});
// Discord Client login
client.login(config.Token);