-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (45 loc) · 1.61 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
'use strict'
const { Client, GatewayIntentBits } = require('discord.js')
const { readdirSync } = require('fs')
const { join } = require('path')
const { bot } = require('config.json')
const CmdList = require('utils/CmdList.js')
const { log } = require('utils/Log.js')
const deployCmd = require('utils/deployCmds.js')
const client = new Client({ intents: [GatewayIntentBits.Guilds] })
client.events = readdirSync(join(__dirname, './events'))
for (let event of client.events) {
if (event.indexOf('Base') !== -1 || event.indexOf('.json') !== -1) {
continue
}
const eventModule = require(`./events/${event}`)
if (typeof eventModule !== 'function') {
log.write('skip bad event:', event)
continue
}
const eventClass = new eventModule()
client.on(eventClass.name, (...args) => {
eventClass.eventCallback(client, ...args)
.catch( (err) => {
log.write(eventClass.name, 'catch error:', err)
client.errHandler.send(err)
})
})
log.write('installed event:', eventClass.name)
}
client.cmdList = new CmdList()
const commands = readdirSync(join(__dirname, './commands'))
for (let cmd of commands) {
if (cmd.indexOf('Base') !== -1 || cmd.indexOf('.json') !== -1) {
continue
}
const cmdModule = require(`./commands/${cmd}`)
if (typeof cmdModule !== 'function') {
log.write('skip bad command:', cmd)
continue
}
const cmdClass = new cmdModule()
client.cmdList.installCmd(cmdClass)
}
deployCmd(client.cmdList.cmdsBuilder.map(command => command.toJSON()))
client.login(bot.token)