-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (42 loc) · 1.49 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
require("dotenv").config();
const { Console } = require("console");
const fs = require("fs");
const {Client, GatewayIntentBits, Collection} = require("discord.js");
const webApi = require('./api/jsonApi');
const dbUtil = require("./util/db")
const logger = new Console({
stdout: process.stdout,
stderr: process.stderr
});
const client = new Client({intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMembers
]});
const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));
const commands = [];
client.commands = new Collection();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
logger.log(`Registered command: ${command.data.name}`);
}
const eventFiles = fs.readdirSync("./events").filter(file => file.endsWith(".js"));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, commands));
} else {
client.on(event.name, (...args) => event.execute(...args, commands));
}
logger.log(`Registered event: ${event.name}`);
}
logger.log("Syncing database...");
dbUtil.syncDb();
client.login(process.env.TOKEN);
webApi.client = client;
const PORT = process.env.API_PORT;
webApi.listen(PORT, () => {
console.log(`HTTP API listening on port ${PORT}`);
});