-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (53 loc) · 1.56 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
const { Client, Intents, Collection } = require("discord.js");
require("dotenv").config();
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILDS,
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.GUILD_BANS,
],
partials: ["MESSAGE", "CHANNEL"],
});
const { createConnection } = require("mysql");
const { readdir } = require("fs");
global.con = createConnection({
host: "localhost",
user: "root",
password: "",
database: process.env.DB_NAME,
});
global.con.connect((err) => {
if (err) throw err;
console.log("Conncted to database");
});
readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.forEach((file) => {
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
});
});
client.slashcommands = new Collection();
client.rawSlashCommands = [];
readdir("./commands/", (err, files) => {
files.forEach((file) => {
const cmd = require(`./commands/${file}`);
cmd.description = cmd.desc;
delete cmd.desc;
if (["USER", "MESSAGE"].includes(cmd.type)) {
cmd.description = "";
delete cmd.options;
}
if (cmd.userPermissions) cmd.defaultPermission = false;
client.rawSlashCommands.push(cmd);
client.slashcommands.set(cmd.name, require(`./commands/${file}`));
});
});
process.on("unhandledRejection", (error) => {
console.error("Unhandled promise rejection:", error);
});
client.login(process.env.TOKEN);