This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
forked from Liga-dos-Programadores/Project-A
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (45 loc) · 1.67 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
48
49
50
51
52
53
54
55
56
57
58
if (process.version.slice(1).split('.')[0] < 8) throw new Error('Node 8.0 ou superior é necessário. Atualize o Node em seu sistema')
require('dotenv').config()
const { Client, Collection } = require('discord.js')
const { readdirSync, lstatSync } = require('fs')
const Enmap = require('enmap')
const client = new Client()
client.commands = new Collection()
client.startTime = Date.now()
loadCommands(client.commands, './commands');
loadEvents('./events');
/*
* Carrega commandos que estão na pasta **commands** e em grupos de subpastas
*/
function loadCommands(collection, directory) {
const cmdFiles = readdirSync(directory);
console.log('log', `Carregando o total de ${cmdFiles.length} comandos em ${directory}`)
for (const file of cmdFiles) {
try {
const path = `${directory}/${file}`;
if (file.endsWith('.js')) {
const command = require(path);
console.log('log', `Carregando comando: ${command.help.name}`)
collection.set(command.help.name, command);
if (command.help.aliases)
command.help.aliases.forEach(alias => collection.set(alias, command))
}
else if (lstatSync(path).isDirectory()) {
loadCommands(collection, path);
}
}
catch (e) {
console.log(`Impossivel executar comando ${file}: ${e}`)
}
}
};
function loadEvents(directory) {
const eventFiles = readdirSync(directory)
console.log('log', `Carregando o total de ${eventFiles.length} eventos`)
for (let file of eventFiles) {
const eventName = file.split('.')[0]
const event = require(`./events/${file}`)
client.on(eventName, event.bind(null, client))
}
}
client.login(process.env.AUTH_TOKEN) /* Inicia o Bot. */