-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
68 lines (56 loc) · 1.56 KB
/
main.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
// import modules
require("dotenv").config()
const path = require("path");
const discord = require("discord.js-commando");
const fastify = require("fastify")();
// init constant value
const TOKEN = process.env.TOKEN;
const COMMAND_DIRECTORY = "commands";
// init instance
const CLIENT = new discord.Client({
owner: "204306814139891712"
});
// define functiond
const registHandring = (client) => {
client
.on('error', console.error)
.on('warn', console.warn)
.on('debug', console.log)
.on('ready', () => {
console.log(`Client ready; logged in as ${client.user.username}#${client.user.discriminator} (${client.user.id})`);
})
.on('disconnect', () => { console.warn('Disconnected!'); })
.on('reconnecting', () => { console.warn('Reconnecting...'); })
};
const registCommands = (client, direcotry) => {
client.registry
.registerDefaultTypes()
.registerGroups([
["git", "GitHub commands"],
["discord", "Discord Util Commands"],
["util", "defualt util commands"]
])
.registerCommandsIn(path.join(__dirname, direcotry))
.registerDefaultCommands({
help: true,
prefix: false,
eval: false,
ping: false,
commandState: false
});
};
// main logic
console.log("starting bot...");
registHandring(CLIENT);
registCommands(CLIENT, COMMAND_DIRECTORY);
CLIENT.login(TOKEN);
console.log("bot is onlined");
// bot server heartbeat from webcron
fastify.get("/", async (req, res) => {
res.type("application/json",).code(200);
return { status:"live" };
});
fastify.listen(3000, (err, address) => {
if (err) throw err
fastify.log.info(`server listening on ${address}`)
})