-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
51 lines (44 loc) · 1.4 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
42
43
44
45
46
47
48
49
50
51
require('dotenv').config();
const Discord = require('discord.js');
const fs = require('fs');
const config = require('./config.json');
const discordToken = process.env.DISCORD_TOKEN;
const client = new Discord.Client();
const COMMANDS_DIR = './commands/';
const EVENTS_DIR = './events/';
client.config = config;
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
fs.readdir(COMMANDS_DIR, (err, files) => {
if (err) {
console.error(err);
} else {
files.forEach(f => {
const props = require(`${COMMANDS_DIR}${f}`);
if (props.conf.enabled) {
client.commands.set(props.conf.name, props);
props.conf.aliases.forEach(alias => {
client.aliases.set(alias, props.conf.name);
});
console.log(`Loaded Command: ${props.conf.name}. 👌`);
}
});
}
});
fs.readdir(EVENTS_DIR, (err, files) => {
if (err) {
console.error(err);
} else {
console.log(`Loading a total of ${files.length} events.`);
files.forEach(f => {
const eventName = f.split(".")[0];
/* eslint-disable-next-line import/no-dynamic-require, global-require */
const event = require(`${EVENTS_DIR}${f}`);
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`${EVENTS_DIR}${f}`)];
});
}
});
client.on('warn', console.warn);
client.on('error', console.error);
client.login(discordToken);