-
Notifications
You must be signed in to change notification settings - Fork 0
/
gerebot.js
77 lines (69 loc) · 2.48 KB
/
gerebot.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Dependencies & instances.
const Discord = require('discord.js');
const { Player } = require('discord-player');
const winston = require('winston');
const client = new Discord.Client();
const logger = winston.createLogger({
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: 'log' }),
],
format: winston.format.printf(
(log) => `[${log.level.toUpperCase()}] - ${log.message}`,
),
});
// Assign instances to client variables (to access globally).
client.Discord = Discord;
client.commands = new Discord.Collection();
client.player = new Player(client);
client.logger = logger;
client.moment = require('moment');
client.axios = require('axios');
client.config = require('./configs/config.json');
client.lang = require('./configs/lang.json');
client.emotes = require('./configs/emotes.json');
client.fs = require('fs');
client.env = require('dotenv').config();
client.cooldowns = new Discord.Collection();
client.language = client.config.language.toLowerCase();
// Get all of the folders that hold commands.
const commandFolders = client.fs.readdirSync('./commands');
// Loop through all of the folders.
for (const folder of commandFolders) {
// Get all of the files in this directory.
const commandFiles = client.fs
.readdirSync(`./commands/${folder}`)
.filter((file) => file.endsWith('.js'));
// Loop through each command and add it to the collection.
for (const file of commandFiles) {
// Sets key in collection with command name & value.
const command = require(`./commands/${folder}/${file}`);
client.commands.set(command.name, command);
client.logger.log(
'info',
`Loaded the ${file.replace('.js', '').toUpperCase()} command file.`,
);
}
}
// Get all of the event files.
const eventFiles = client.fs.readdirSync('./events');
// Loop through all of the events registering them.
for (const file of eventFiles) {
const event = require(`./events/${file}`);
client.on(file.split('.')[0], event.bind(null, client));
client.logger.log(
'info',
`Loaded the ${file.replace('.js', '').toUpperCase()} event file.`,
);
}
const playerEventFiles = client.fs.readdirSync('./player');
for (const file of playerEventFiles) {
const event = require(`./player/${file}`);
client.player.on(file.split('.')[0], event.bind(null, client));
client.logger.log(
'info',
`Loaded the ${file.replace('.js', '').toUpperCase()} event file.`,
);
}
// Login with the token.
client.login(client.env.parsed.DISCORD_TOKEN);