This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
index.js
151 lines (128 loc) · 4.17 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
const express = require('express');
const app = express();
app.get('/', function (request, response) {
response.sendFile(__dirname + '/index.html');
});
app.use('/ping', (req, res) => {
res.send(new Date());
});
app.listen(9080, () => {
console.log(('Express is ready.').blue.bold)
});
const { Client, Collection, Partials, GatewayIntentBits, ActionRowBuilder, ButtonBuilder, ButtonStyle, Events, EmbedBuilder } = require('discord.js');
const config = require("./config.json");
const { glob } = require("glob");
const { promisify } = require("util");
const { joinVoiceChannel } = require('@discordjs/voice');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { SlashCommandBuilder } = require('@discordjs/builders');
const db = require('quick.db');
const colors = require("colors");
// const pathToFfmpeg = require('ffmpeg-static')
// console.log(pathToFfmpeg)
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.MessageContent
],
partials: [
Partials.Message,
Partials.Channel,
Partials.GuildMember,
Partials.Reaction,
Partials.GuildScheduledEvent,
Partials.User,
Partials.ThreadMember
],
shards: "auto",
allowedMentions: {
parse: [],
repliedUser: false
},
})
client.setMaxListeners(25);
require('events').defaultMaxListeners = 25;
const { createLogger, transports, format } = require('winston');
const path = require('path');
const logger = createLogger({
level: 'error',
format: format.combine(
format.timestamp(),
format.json(),
),
transports: [
new transports.File({ filename: path.join(__dirname, 'Logs', 'Errors.json') }),
],
});
client.on('error', error => {
console.error('Discord.js error:', error);
logger.error('Discord.js error:', error);
});
client.on('warn', warning => {
console.warn('Discord.js warning:', warning);
});
let antiCrashLogged = false;
process.on('unhandledRejection', (reason, p) => {
if (!antiCrashLogged) {
console.error('[antiCrash] :: Unhandled Rejection/Catch');
console.error(reason, p);
logger.error('[antiCrash] :: Unhandled Rejection/Catch', { reason, p });
antiCrashLogged = true;
}
});
process.on('uncaughtException', (err, origin) => {
if (!antiCrashLogged) {
console.error('[antiCrash] :: Uncaught Exception/Catch');
console.error(err, origin);
logger.error('[antiCrash] :: Uncaught Exception/Catch', { err, origin });
antiCrashLogged = true;
}
});
process.on('uncaughtExceptionMonitor', (err, origin) => {
if (!antiCrashLogged) {
console.error('[antiCrash] :: Uncaught Exception/Catch (MONITOR)');
console.error(err, origin);
logger.error('[antiCrash] :: Uncaught Exception/Catch (MONITOR)', { err, origin });
antiCrashLogged = true;
}
});
module.exports = client;
client.commands = new Collection();
client.events = new Collection();
client.slashCommands = new Collection();
['commands', 'events', 'slash'].forEach(handler => {
require(`./handlers/${handler}`)(client);
})
const commands = client.slashCommands.map(({ execute, ...data }) => data);
// Register slash commands
const rest = new REST({ version: '9' }).setToken(config.token || process.env.token);
rest.put(
Routes.applicationGuildCommands(config.clientID, config.guildID),
{ body: commands },
).then(() => console.log('Successfully registered application commands.'))
.catch(console.error)
setTimeout(() => {
if (!client || !client.user) {
console.log("Client Not Login, Process Kill")
process.kill(1);
} else {
console.log("Client Login")
}
}, 5 * 1000 * 60);
client.login(config.token || process.env.token).catch((err) => {
console.log(err.message)
})