-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (34 loc) · 1.1 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
// Library calls
const Discord = require("discord.js");
const client = new Discord.Client();
let { readdirSync } = require("fs");
// Config calls
client.config = require("./config.js");
client.commands = new Discord.Collection();
// Command Handler / Setup.
for (const file of readdirSync("./commands/")) {
if (!file.endsWith(".js")) return;
let fileName = file.substring(0, file.length - 3);
let fileContents = require(`./commands/${file}`);
client.commands.set(fileName, fileContents);
}
// Event Handler / Setup.
for (const file of readdirSync("./events/")) {
if (!file.endsWith(".js")) return;
let fileName = file.substring(0, file.length - 3);
let fileContents = require(`./events/${file}`);
client.on(fileName, fileContents.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
}
// Log in and error handling
client
.login(client.config.token)
.then(() => {
if (!client.user.bot) {
return process.exit();
}
console.log(`Client logged in as ${client.user.tag}`);
})
.catch((err) => {
console.error("Error while logging in: " + err);
});