forked from Buddier/Discord.js-v13-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
172 lines (148 loc) · 6.04 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env node
// -*- coding: utf-8 -*-
console.clear();
console.debug(`Booting up…`);
/// Declaring variables for 3rd side libs
const _discord_js = require('discord.js');
const {
Client,
Collection,
Intents
} = _discord_js
//const Discord = require('discord.js');
const discordModals = require('discord-modals');
const path = require('path');
const dotenv = require('dotenv');
/* const { Permissions } = require('discord.js');
const fs = require('fs').promises;
const { MessageActionRow, MessageButton, Permissions, Formatters } = require('discord.js');
const { Modal, TextInputComponent, showModal } = require('discord-modals'); // Now we extract the showModal method
const { MessageButton, Permissions } = require('discord.js');
const { Formatters } = require('discord.js'); */
/// Declaring custom variables for local developments
//const handler = require(process.cwd() + '\\handler\\index');
//const chalkMy = require(process.cwd() + '\\src\\chalk');
//const process = require('process');
//const os = require('os');
/// Declaring main var — client
const client = new Client({ intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_BANS,
Intents.FLAGS.GUILD_INTEGRATIONS,
Intents.FLAGS.GUILD_WEBHOOKS,
Intents.FLAGS.GUILD_INVITES,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_MESSAGE_TYPING,
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGE_TYPING,
] });
/// Custom Global Variables
client.g = {};
client.g.cwd = require('process').cwd(); // require('path').resolve(``);
client.g.config = require(client.g.cwd + '\\config');
client.g.chalk = require(client.g.cwd + '\\src\\custom\\chalk');
client.g.database = require(client.g.cwd + '\\src\\custom\\database').load(client.g.cwd);
client.g.handlers = {
OS: {
eventsProcess: require(client.g.cwd + '\\src\\handlers\\OS\\process\\eventsProcess'),
},
Discord: {
eventsDiscord: require(client.g.cwd + '\\src\\handlers\\Discord\\eventsDiscord'),
cmdsSlash: require(client.g.cwd + '\\src\\handlers\\Discord\\cmdsSlash'),
cmdsLegacy: require(client.g.cwd + '\\src\\handlers\\Discord\\cmdsLegacy')
}
};
//client.handler = require(client.g.cwd + '\\handlers\\index');
client.g.discord = _discord_js;
client.g.cmds = {};
client.g.cmds.legacy = new Collection();
client.g.cmds.slash = new Collection();
//client.g.config.verbose = Boolean(0);
//client.g.config.debug = Boolean(0);
/// Call .env file to get Token
const result = dotenv.config({
debug: Boolean( 0 ),
path: path.resolve(client.g.cwd, '.env')
});
if (result.error) throw result.error;
/// Enabling work with Modals
discordModals(client);
/// Exporting client data
module.exports = client;
/// Records commands and events
//client.g.handlers.OS.eventsProcess.load(client); // ToDo: BROKEN, DO NOT USE
client.g.handlers.Discord.eventsDiscord.load(client);
client.g.handlers.Discord.cmdsLegacy.load(client);
client.g.handlers.Discord.cmdsSlash.load(client);
/// Error Handling
process.on('uncaughtException', (e) => {
console.error(client.g.chalk.exct, `Uncaught Exception:`);
console.error(e);
});
process.on('unhandledRejection', (reason, promise) => {
console.error(client.g.chalk.fatal, `Possibly Unhandled Rejection:`);
console.error(promise);
console.error(reason);
//console.error(`httpStatus: ${reason.httpStatus}, reason: ${reason.message}`);
/// Below - detailing for 'DiscordAPIError: Invalid Form Body'
if (!reason.requestData) return;
if (!reason.requestData['json']) return console.error(reason.requestData);
return console.error(reason.requestData['json']);
/* if (reason.code == 50035 || reason.message == 'Invalid Form Body') {
if (reason.requestData['json'] == []) return;
if (!reason.requestData['json'][0]) return;
if (!reason.requestData['json'][0].name) return;
if (!reason.requestData['json'][0].description) return;
for (let i = 0; i < reason.requestData['json'].length; i++) {
let cmd = reason.requestData['json'][i];
let ii = i < 10 ? ` ${i}`: i;
let iii = cmd.name.length < 10 ? ` ${cmd.name.length}`: cmd.name.length;
let iiii = cmd.description.length < 100 ? cmd.description.length < 10 ? ` ${cmd.description.length}`: ` ${cmd.description.length}`: cmd.description.length;
console.error(`[${ii}/${reason.requestData['json'].length - 1}] (${iii}/32;${iiii}/100) '${cmd.name}', '${cmd.description}'`);
}
//console.error(reason.requestData['json']);
} else {
console.error(reason.requestData['json']);
} */
});
/// Fancy shutdown
process.on('SIGINT', () => {
console.log(client.g.chalk.exit, `Caught interrupt signal.`);
/* try {
client.user.setStatus('invisible');
} catch (e) {
console.log(client.g.chalk.fatal, `Can not set status.`);
} */
if (client.isReady()) client.user.setStatus('invisible');
/* client.guilds.cache.forEach(guild => {
if (client.playerManager.get(guild)) client.playerManager.leave(guild);
}); */
client.destroy();
process.exit();
});
process.on('SIGTERM', () => {
console.log(client.g.chalk.exit, `Caught termination signal.`);
/* try {
client.user.setStatus('invisible');
} catch (e) {
console.log(client.g.chalk.fatal, `Can not set status.`);
} */
if (client.isReady()) client.user.setStatus('invisible');
/* client.guilds.cache.forEach(guild => {
if (client.playerManager.get(guild)) client.playerManager.leave(guild);
}); */
client.destroy();
process.exit();
});
/// Fancy login
async function clientLogin() {
// Login into Discord via Bot Token
console.log(client.g.chalk.log, `All preparations done, logging in…`);
await client.login(process.env.TOKEN);
}
clientLogin();