-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
166 lines (130 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const express = require("express");
const app = express();
const port = 3000;
app.get("/", (req, res) => res.send("bot online yay boy!!"));
app.listen(port, () =>
console.log(`Your app is listening a http://localhost:${port}`)
);
require("dotenv").config();
("$TOEKN");
const db = require("quick.db");
const { emotes, emoji } = require("./config.json");
const { EmbedBuilder } = require("discord.js");
const discord = require("discord.js");
const { Client, Events, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.MessageContent,
],
});
const colors = require("./colors.json");
const yts = require("yt-search");
const fs = require("node:fs");
const { readdirSync } = require("node:fs");
const enmap = require("enmap");
const { guildId } = require("./config.json");
client.queue = new Map();
client.vote = new Map();
// Command Handler
["command"].forEach((handler) => {
require(`./handlers/${handler}`)(client);
});
["slash-command"].forEach((handler) => {
require(`./handlers/${handler}`)(client);
});
require("./deploy-commands.js");
client.queue = new Map();
client.snipes = new Map();
client.on("messageDelete", function (message, channel) {
client.snipes.set(message.channel.id, {
content: message.content,
author: message.author.tag,
image: message.attachments.first()
? message.attachments.first().proxyURL
: null,
});
});
// Giveaway
const { GiveawaysManager } = require("discord-giveaways");
const manager = new GiveawaysManager(client, {
storage: "./giveaways.json",
updateCountdownEvery: 10000,
default: {
botsCanWin: false,
exemptPermissions: ["MANAGE_MESSAGES", "ADMINISTRATOR"],
embedColor: "#FF0000",
reaction: "🎉",
},
});
client.giveawaysManager = manager;
// Event handler
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, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
};
const { Player } = require("discord-music-player");
const player = new Player(client, {
leaveOnEmpty: false,
});
// Error Handling
process.on("uncaughtException", (err) => {
let ErrorLoggingChannel = db.get(`ErrorLoggingChannel_${guildId}`);
if (!ErrorLoggingChannel)
return console.log(
`Setup Is Not Done in ${guild} aka ${guild} Guild (channel not found)`
);
console.log(err);
const exceptionembed = new EmbedBuilder()
.setTitle("Uncaught Exception")
.setDescription(`\`\`\`${require('util').inspect(err)}\`\`\``)
.setColor("Red");
client.channels.cache.get(ErrorLoggingChannel).send({ embeds: [exceptionembed] });
});
process.on("unhandledRejection", (reason, promise) => {
let ErrorLoggingChannel = db.get(`ErrorLoggingChannel_${guildId}`);
if (!ErrorLoggingChannel)
return console.log(
`Setup Is Not Done in ${guild} aka ${guild} Guild (channel not found)`
);
console.log(
"[FATAL] Possibly Unhandled Rejection at: Promise ",
promise,
" reason: ",
reason.message
);
const rejectionembed = new EmbedBuilder()
.setTitle("Unhandled Promise Rejection")
.addFields([
{ name: "Promise", value: `\`\`\`${require('util').inspect(promise).slice(0, 1010)}\`\`\`` },
{ name: "Reason", value: `${reason.message}` }
])
.setColor("Red");
client.channels.cache.get(ErrorLoggingChannel).send({ embeds: [rejectionembed] });
});
client.player = player;
new Player(client, {
leaveOnEnd: true,
leaveOnStop: true,
leaveOnEmpty: true,
timeout: 10,
volume: 150,
quality: "high",
});
client.login(process.env.TOKEN);