-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (62 loc) · 2.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require('dotenv').config();
const { Client, Collection, GatewayIntentBits, Partials } = require("discord.js");
const client = new Client({intents: [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages], partials: [Partials.Message, Partials.Channel, Partials.GuildMember, Partials.User]});
const config = require("./src/config.js");
const { readdirSync } = require("fs");
const moment = require("moment");
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v10');
const { log } = require("./src/util/utilfunctions");
const { QuickDB } = require("quick.db");
const db = new QuickDB();
client.prefixcommands = new Collection();
client.slashcommands = new Collection();
client.commandaliases = new Collection();
//slash-command-handler
const slashcommands = [];
readdirSync('./src/commands/slash').forEach(async file => {
const command = await require(`./src/commands/slash/${file}`);
slashcommands.push(command.data.toJSON());
await db.get("slashcommands");
await db.set("slashcommands", slashcommands);
client.slashcommands.set(command.data.name, command);
});
//prefix-command-handler
const prefixcommands = [];
readdirSync('./src/commands/prefix').forEach(async file => {
const command = await require(`./src/commands/prefix/${file}`);
if(command) {
client.prefixcommands.set(command.name, command);
prefixcommands.push(command.name, command);
if(command.aliases && Array.isArray(command.aliases)) {
command.aliases.forEach(alias => {
client.commandaliases.set(alias, command.name);
});
}
}
});
//event-handler
readdirSync('./src/events').forEach(async file => {
const event = await require(`./src/events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
});
//nodejs-events
function announceError(error) {
console.error("\x1b[41m");
console.error(error);
console.error("\x1b[0m");
};
process.on("unhandledRejection", e => {
announceError(e);
})
process.on("uncaughtException", e => {
announceError(e);
})
process.on("uncaughtExceptionMonitor", e => {
announceError(e);
})
client.login(process.env.DISCORD_TOKEN);