This repository has been archived by the owner on Apr 26, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcore.js
67 lines (52 loc) · 1.68 KB
/
core.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
/*
@document : core.js
@author : Thomas Bnt <thomasbnt@protonmail.com>
@version : 1.1.0
@copyright : 2020, Thomas Bnt
@license : GNU General Public License v3.0
@repository : https://github.com/lahype/DefaultCommandHandlerWithShardingManager
*/
const Discord = require('discord.js')
const fs = require('fs')
const klaw = require('klaw')
const path = require("path")
const config = require('./config.json')
const bot = new Discord.Client({
autoReconnect: true
})
// -------------------- Config --------------------
bot.config = config
bot.commands = new Discord.Collection()
bot.updatePresence = function updatePresence() {
bot.user.setActivity("my custom status", { type: "WATCHING" })
}
// -------------------- My C0re --------------------
fs.readdir('./events/', (err, files) => {
if (err) return console.error(err)
files.forEach(file => {
const event = require(`./events/${file}`)
let eventName = file.split('.')[0]
bot.on(eventName, event.bind(null, bot))
})
})
klaw("./commands/").on("data", (item) => {
const cmdFile = path.parse(item.path)
if (!cmdFile.ext || cmdFile.ext !== ".js") return
let commandName = cmdFile.name.split(".")[0]
const response = _loadCommand(cmdFile.dir, `${commandName}`)
if (response) console.log(response)
})
function _loadCommand (commandPath, commandName) {
try {
console.log(`Loading Command: ${commandName}`)
const props = require(`${commandPath}${path.sep}${commandName}`)
if (props.init) {
props.init(bot)
}
bot.commands.set(commandName, props)
return false
} catch (e) {
return `Unable to load command ${commandName}: ${e}`
}
}
bot.login(config.token)