-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
105 lines (95 loc) · 4.48 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Load required resources =================================================================================================
const { Client, GatewayIntentBits, Partials, Collection } = require('discord.js');
const path = require('path');
const fs = require('fs');
// Load configuration files ================================================================================================
const { token } = require(path.resolve('./config/bot'));
// Define client Intents ===================================================================================================
const client = new Client({
intents: [
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping
],
partials: [
Partials.Channel,
Partials.GuildMember,
Partials.GuildScheduledEvent,
Partials.Message,
Partials.Reaction,
Partials.ThreadMember,
Partials.User
]
});
// Track load time =========================================================================================================
client.startupTime = Date.now();
// Admin Commands (with prefix) ============================================================================================
try {
client.commandsPrefix = new Collection();
var pathFiles = './commands';
fs.readdirSync(pathFiles).forEach(folder => {
fs.readdirSync(`${pathFiles}/${folder}`).filter(file => file.endsWith('.js')).forEach((file) => {
client.commandsPrefix.set(file.split(".")[0], require(path.resolve(path.join(`${pathFiles}/${folder}`, file))));
});
});
} catch(error) {
console.error('[load:cmds]', error.message);
}
// Interactions :: SlashCommands ===========================================================================================
try {
client.slashRegister = [];
client.interactionsSlash = new Collection();
var pathFiles = './interactions/slashCommands';
fs.readdirSync(pathFiles).forEach(folder => {
fs.readdirSync(`${pathFiles}/${folder}`).filter(file => file.endsWith('.js')).forEach((file) => {
var command = require(path.resolve(path.join(`${pathFiles}/${folder}`, file)));
client.slashRegister.push(command.data.toJSON());
client.interactionsSlash.set(command.data.name, command);
});
});
} catch(error) {
console.error('[load:interactions:slash]', error.message);
}
// Interactions :: Buttons =================================================================================================
try {
client.interactionsButtons = new Collection();
var pathFiles = './interactions/buttons';
fs.readdirSync(pathFiles).forEach(folder => {
fs.readdirSync(`${pathFiles}/${folder}`).filter(file => file.endsWith('.js')).forEach((file) => {
client.interactionsButtons.set(file.split(".")[0], require(path.resolve(path.join(`${pathFiles}/${folder}`, file))));
});
});
} catch(error) {
console.error('[load:interactions:button]', error.message);
}
// Handle :: Events ========================================================================================================
try {
var pathFiles = './events';
fs.readdirSync(pathFiles).forEach(folder => {
fs.readdirSync(`${pathFiles}/${folder}`).filter(file => file.endsWith('.js')).forEach((file) => {
const event = require(path.resolve(path.join(`${pathFiles}/${folder}`, file)));
client.on(event.name, (...args) => event.execute(...args));
});
});
} catch(error) {
console.error('[load:events]', error.message);
}
// Define token a init bot =================================================================================================
client.login(token).then(() => {
console.log(`[init] Bot operativo | Inicializado en ${Date.now() - client.startupTime}ms`);
}).catch((error) => {
console.error('[client:token]', error.message);
});
// Handle Error ============================================================================================================
process.on('unhandledRejection', (error) => {
console.error('[process:unhandledError]', error.message);
});
client.on('shardError', (error) => {
console.error('[process:shardError]', error.message);
});