forked from bastianleicht/DiscordJS-Bot-Base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (38 loc) · 1.31 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
/*
* Copyright (c) 2020-2021, Bastian Leicht <[email protected]>
*
* PDX-License-Identifier: BSD-2-Clause
*/
const Discord = require("discord.js");
const client = new Discord.Client();
const fs = require("fs");
const Enmap = require("enmap");
const config = require("./config.json");
client.config = config;
client.commands = new Enmap();
console.log("------------------------------------------------");
fs.readdir("./events/", (err, files) => {
if (err) return console.error;
files.forEach((file) => {
if (!file.endsWith(".js")) return;
const evt = require(`./events/${file}`);
let evtName = file.split(".")[0];
console.log(`Loaded event '${evtName}'`);
client.on(evtName, evt.bind(null, client));
});
console.log("------------------------------------------------");
});
fs.readdir("./commands/", async (err, files) => {
files.forEach((file) => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let cmdName = file.split(".")[0];
console.log(`Loaded Command '${cmdName}'`);
client.commands.set(cmdName, props);
});
console.log("------------------------------------------------");
});
process.on("unhandledRejection", (error) => {
console.error("Unhandled promise rejection:", error);
});
client.login(config.token || process.env.TOKEN);