-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
81 lines (73 loc) · 2.26 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
// TODO: Agregar cooldown
const fs = require("fs");
require("dotenv").config();
const { Client, Collection, Intents } = require("discord.js");
const BcK = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_VOICE_STATES,
],
partials: ["MESSAGE", "CHANNEL", "REACTION", "GUILD_MEMBER"],
});
const prefix = process.env.PREFIX_MAIN;
const commandFolders = fs.readdirSync("./commands");
BcK.commands = new Collection();
BcK.auto_commands = new Collection();
for (const folder of commandFolders) {
const commandFiles = fs
.readdirSync(`./commands/${folder}`)
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`./commands/${folder}/${file}`);
if (command.data?.name !== undefined) {
BcK.commands.set(command.data.name, command);
} else if (command?.name.includes("auto")) {
BcK.auto_commands.set(command.name, command);
}
}
}
const eventFiles = fs
.readdirSync("./events")
.filter((file) => file.endsWith(".js"));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
BcK.once(event.name, (...args) => event.execute(...args, BcK));
} else {
BcK.on(event.name, (...args) => event.execute(...args, BcK));
}
}
// CommandHandler
BcK.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) return;
const command = BcK.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction, BcK);
} catch (error) {
console.error(error);
await interaction.reply({
content: "Hubo un error al ejecutar este comando!",
ephemeral: true,
});
BcK.users.cache
.get("443998731310858242")
.send(
`Hubo un error en el modulo: ${prefix} **${interaction.commandName}**`
);
BcK.users.cache.get("443998731310858242").send(`\`\`\`${error}\`\`\``);
}
});
// Log In
console.log("%c\tLog-in client...", "background: teal; color: white");
BcK.login(process.env.TOKEN);
// Servidor WEB
const http = require("http");
const server = http.createServer((req, res) => {
res.writeHead(200);
res.end("ok");
});
server.listen(3000);