-
Notifications
You must be signed in to change notification settings - Fork 3
/
bot.js
41 lines (35 loc) · 1.24 KB
/
bot.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
const botSettings = require("./botsettings.json");
const Discord = require("discord.js");
const fs = require("fs");
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
// Command Handler
fs.readdir("./commands/", (err, files) => {
if (err) console.error(err);
let jsfiles = files.filter(f => f.split(".").pop() === "js");
if (jsfiles.length <= 0) {
console.log("");
console.log("No commands to be loaded!");
return;
}
// console.log(`\nLoading ${jsfiles.length} commands!\n`)
jsfiles.forEach(f => {
let props = require(`./commands/${f}`);
bot.commands.set(props.help.name, props);
});
console.log(`[Commands]\t Loaded ${jsfiles.length} commands!`);
});
// Event Handler
fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.filter(file => {
let eventFunction = require(`./events/${file}`);
let eventName = file.split(".")[0];
if(eventFunction.length <= 0) {
console.log("No Events to load!");
return;}
bot.on(eventName, eventFunction.run.bind(null, bot));
});
console.log(`[Events]\t Loaded a total amount of ${files.length} events!`);
});
bot.login(botSettings.token);