forked from Liga-dos-Programadores/Project-A
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (33 loc) · 1.32 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
if (process.version.slice(1).split('.')[0] < 8) throw new Error('Node 8.0.0 or higher is required. Update Node on your system.')
require('dotenv').config()
const Discord = require('discord.js')
const { readdirSync } = require('fs')
const Enmap = require('enmap')
const client = new Discord.Client()
client.commands = new Enmap()
client.startTime = Date.now()
const cmdFiles = readdirSync('./commands/')
console.log('log', `Carregando o total de ${cmdFiles.length} comandos.`)
cmdFiles.forEach(f => {
try {
const props = require(`./commands/${f}`)
if (f.split('.').slice(-1)[0] !== 'js') return
console.log('log', `Carregando comando: ${props.help.name}`)
if (props.init) props.init(client)
client.commands.set(props.help.name, props)
if (props.help.aliases) {
props.alias = true
props.help.aliases.forEach(alias => client.commands.set(alias, props))
}
} catch (e) {
console.log(`Impossivel executar comando ${f}: ${e}`)
}
})
const evtFiles = readdirSync('./events/')
console.log('log', `Carregando o total de ${evtFiles.length} eventos`)
evtFiles.forEach(f => {
const eventName = f.split('.')[0]
const event = require(`./events/${f}`)
client.on(eventName, event.bind(null, client))
})
client.login(process.env.AUTH_TOKEN) /* Inicia o Bot. */