/
praetor.js
64 lines (56 loc) · 2.05 KB
/
praetor.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
const path = require('node:path');
const { Client, GatewayIntentBits, Partials, Collection } = require('discord.js');
const { token } = require('./auth.json');
const { getFiles, getFilepaths, logError } = require('./utils');
const clientOptions = {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildScheduledEvents,
GatewayIntentBits.AutoModerationConfiguration,
GatewayIntentBits.AutoModerationExecution
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
};
const client = new Client(clientOptions);
client.commands = new Collection();
// Set up commands
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = getFilepaths(commandsPath);
for (const filepath of commandFiles) {
const command = require(filepath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filepath} is missing a required "data" or "execute" property.`);
}
}
// Set up event listeners
const eventsPath = path.join(__dirname, 'events');
const eventsFiles = getFiles(eventsPath);
for (const event of eventsFiles) {
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
// default promise rejection handling
process.on('unhandledRejection', err => logError(client, err));
// last ditch error handling
process.on('uncaughtException', err => logError(client, err));
client.login(token);