-
Notifications
You must be signed in to change notification settings - Fork 0
/
praetor.js
67 lines (58 loc) · 2.2 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
65
66
67
import path from 'node:path';
import { Client, GatewayIntentBits, Partials, Collection } from 'discord.js';
import auth from './auth.json' with { type: "json"};
import { getFiles, getFilepaths, logError } from './utils.js';
import { fileURLToPath, pathToFileURL } from 'node:url';
const clientOptions = {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildModeration,
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();
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Set up commands
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = getFilepaths(commandsPath);
for (const filepath of commandFiles) {
const command = await import(pathToFileURL(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 = await 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(auth.token);