-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
554 lines (522 loc) · 17.6 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
(async () => {
const {
Client,
GatewayIntentBits,
Partials,
Collection,
Discord,
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
Events,
ActivityType,
TextInputStyle,
TextInputBuilder,
ModalBuilder,
InteractionType,
} = require("discord.js"); // Discord.js V14
const { default: mongoose } = require("mongoose"); // Mongoose
const chalk = require("chalk");
const config = require("./config.js"); // Config
const i18next = require("i18next"); // i18next
const { t } = require("i18next"); // i18next Translate
const translationBackend = require("i18next-fs-backend"); // i18next-fs-backend
const { readdirSync } = require("fs");
const moment = require("moment"); // Moment
const timezones = require("moment-timezone"); // Moment Timezone
const { REST } = require("@discordjs/rest"); // Discord.js REST
const { Routes } = require("discord-api-types/v10"); // Discord.js Routes
const { DisTube } = require("distube"); // DisTube
const { SpotifyPlugin } = require("@distube/spotify"); // DisTube Spotify Plugin
const { SoundCloudPlugin } = require("@distube/soundcloud"); // DisTube SoundCloud Plugin
const { YtDlpPlugin } = require("@distube/yt-dlp"); // DisTube YtDlp Plugin
const { Player } = require("discord-player"); // Discord Player
const music_mongo = require("./models/music.js"); // Music Model
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildBans,
],
}); // Client
const player = new Player(client);
client.player = player;
client.distube = new DisTube(client, {
leaveOnStop: false,
leaveOnEmpty: true,
leaveOnFinish: true,
emitNewSongOnly: true,
emitAddSongWhenCreatingQueue: false,
emitAddListWhenCreatingQueue: false,
plugins: [
new SpotifyPlugin({
emitEventsAfterFetching: true,
}),
new SoundCloudPlugin(),
new YtDlpPlugin(),
],
});
require("./loader.js")(client); // Loader
mongoose
.connect(config.mongodb, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log(
chalk.bold.yellow(`[MongoDB]:`),
chalk.bold.blue(`MongoDB Database Connected!`)
);
})
.catch((err) => {
console.log(
chalk.hex("#FF0000").bold(`[MongoDB]:`),
chalk.bold.blue(`MongoDB Database Connection Failed! Error: ${err}`)
);
}); // MongoDB Connection
client
.login(config.token)
.then(() => {
console.log(
chalk.hex("#067A00").bold(`[Bot]:`),
chalk.bold.blue(`${client.user.tag} Login Succesfully`)
); // Giriş başarılıysa bot aktif olur.
})
.catch((err) => {
console.log(chalk.hex("#FF0000").bold(`Entry failed!${err}`)); // Giriş başarısızsa hata verir.
});
// Initialize multi language system
i18next.use(translationBackend).init({
ns: readdirSync("./locales/en-US").map((a) => a.replace(".json", "")),
defaultNS: "commands",
fallbackLng: "en-US",
preload: readdirSync("./locales"),
backend: {
loadPath: "./locales/{{lng}}/{{ns}}.json",
},
}); // i18next
client.on("ready", async () => {
client.guilds.cache.filter(async (guild) => {
const data = await music_mongo.find({});
if (!data) return;
await music_mongo.remove({}).catch((err) => {});
});
console.log(
chalk.bold.magenta(`[SlashCommands]:`),
chalk.bold.blue(`${client.slashCommands.size} commands loaded.`)
); // Slash Commands
var status = config.ready; // Ready Status
setInterval(function () {
client.user.setActivity(
` ${status[Math.floor(Math.random() * status.length)]}`,
{
type: ActivityType.Listening,
}
);
}, config.ready_event_loop_time); // Ready Event Loop Time (ms) 5000ms = 5s
}); // Ready Event
client.distube.on("finish", async (queue) => {
client.guilds.cache.filter(async (guild) => {
const data = await music_mongo.findOne({ guildId: guild.id });
if (!data) return;
const message = data.interactionId;
const channels = data.channelId;
const channel = guild.channels.cache.get(channels);
const finished = new EmbedBuilder()
.setTitle("Song Finished!")
.setDescription("You can use the /play command to start a new song")
.setFooter({
text: `${config.footer.text}`,
iconURL: `${config.footer.icon}`,
});
channel.send({ embeds: [finished], components: [] })
.catch((err) => {});
});
}); // DisTube Finish Event
client.distube.on("empty", async (queue) => {
const data = await music_mongo.findOne({ guildId: queue.id });
if (!data) return;
const empty = new EmbedBuilder()
.setTitle("Hey!")
.setDescription("Channel is empty. Leaving the channel")
.setFooter({
text: `${config.footer.text}`,
iconURL: `${config.footer.icon}`,
})
.setColor(config.embed.error);
const channelleave = client.channels.cache.get(data.channelId);
channelleave.send({ embeds: [empty] }).catch((err) => {});
}); // DisTube Empty Event
client.distube.on("error", (channel, e) => {
if (channel) channel.send(`An error encountered: ${e}`);
else console.error(e);
});
client.distube.on("searchCancel", (interaction) => {
const cancelsearch = new EmbedBuilder()
.setTitle("Cancelled!")
.setDescription("Searching canceled, Please try Again.")
.setFooter({
text: `${config.footer.text}`,
iconURL: `${config.footer.icon}`,
})
.setColor(config.embed.error);
interaction.channel.send({ embeds: [cancelsearch] }).catch((err) => {});
});
client.distube.on("searchInvalidAnswer", (message) => {
message.channel.send(`You answered an invalid number!`).catch((err) => {});
});
client.distube.on("searchNoResult", (message, query) => {
message.channel.send(`No result found for ${query}!`).catch((err) => {});
});
//Volume Play commands Volume
client.on("interactionCreate", async (interaction) => {
if (interaction.isButton()) {
if (interaction.customId == "volume") {
const modalvolume = new ModalBuilder()
.setCustomId("formvolume")
.setTitle("Set Volume");
const a1 = new TextInputBuilder()
.setCustomId("setvolume")
.setLabel("Volume")
.setStyle(TextInputStyle.Paragraph)
.setMinLength(1)
.setPlaceholder("1 - 100")
.setRequired(true);
const row = new ActionRowBuilder().addComponents(a1);
modalvolume.addComponents(row);
await interaction.showModal(modalvolume)
}
}
});
client.on("interactionCreate", async (interaction) => {
if (interaction.type !== InteractionType.ModalSubmit) return;
if (interaction.customId === "formvolume") {
const string = interaction.fields.getTextInputValue("setvolume");
const volume = parseInt(string);
const queue = client.distube.getQueue(interaction);
if (!queue)
return interaction
.reply(`There is no song on the list yet.`)
.catch((err) => {});
if (isNaN(volume))
return interaction.reply("Give me number!").catch((err) => {});
if (volume < 1)
return interaction
.reply("The number must not be less than 1.")
.catch((err) => {});
if (volume > 100)
return interaction
.reply("The number should not be greater than 100.")
.catch((err) => {});
client.distube.setVolume(interaction, volume)
interaction
.reply("Successfully set the volume of the music to **" + volume + "**")
.catch((err) => {});
}
});
//Play Command Volume
//Skip Command Volume
client.on("interactionCreate", async (interaction) => {
if (interaction.isButton()) {
if (interaction.customId == "volumes") {
const modalvolume = new ModalBuilder()
.setCustomId("formvolumes")
.setTitle("Set Volume");
const a1 = new TextInputBuilder()
.setCustomId("setvolumes")
.setLabel("Volume")
.setStyle(TextInputStyle.Paragraph)
.setMinLength(1)
.setPlaceholder("1 - 100")
.setRequired(true);
const row = new ActionRowBuilder().addComponents(a1);
modalvolume.addComponents(row);
await interaction.showModal(modalvolume)
}
}
});
client.on("interactionCreate", async (interaction) => {
if (interaction.type !== InteractionType.ModalSubmit) return;
if (interaction.customId === "formvolumes") {
const string = interaction.fields.getTextInputValue("setvolumes");
const volume = parseInt(string);
const queue = client.distube.getQueue(interaction);
if (!queue)
return interaction
.reply(`There is no song on the list yet.`)
.catch((err) => {});
if (isNaN(volume))
return interaction.reply("Give me number!").catch((err) => {});
if (volume < 1)
return interaction
.reply("The number must not be less than 1.")
.catch((err) => {});
if (volume > 100)
return interaction
.reply("The number should not be greater than 100.")
.catch((err) => {});
client.distube.setVolume(interaction, volume)
interaction
.reply("Successfully set the volume of the music to **" + volume + "**")
.catch((err) => {});
}
});
//Skip Command Volume
//Loop Command Play
client.on("interactionCreate",async (interaction) => {
if (interaction.customId === "loop") {
const queue = client.distube.getQueue(interaction);
if (!queue) return interaction.reply(`${t("error.nosonglist", {
ns: "common",
lng: interaction.locale,
})}`)
let data = await music_mongo.findOne({ guildId: interaction.guild.id });
if (!data) return interaction.reply({content: `${t("error.dataerror", {
ns: "common",
lng: interaction.locale,
})}`, ephemeral: true})
let userr = data.userId
if (interaction.user.id !== userr) return interaction.reply({content: `${t("error.onlyuser", {
ns: "common",
lng: interaction.locale,
})}`, ephemeral: true})
const title = data.title
const author = data.uploader
const time = data.time
const view = data.views
const thumb = data.thumbnail
const url = data.video
const views = view;
function formatNumber(views) {
if (views >= 1000000000) {
return (views / 1000000000).toFixed(1) + "B";
} else if (views >= 1000000) {
return (views / 1000000).toFixed(1) + "M";
} else if (views >= 1000) {
return (views / 1000).toFixed(1) + "K";
}
return views;
}
if (queue.repeatMode === 0) {
const embed = new EmbedBuilder()
.setTitle(
`${t("succes.songloopon", {
ns: "common",
lng: interaction.locale,
})}`
)
.setDescription(`**[${queue.songs[0].name}](${queue.songs[0].url})**`)
.addFields(
{
name: `${t("music.author", {
ns: "common",
lng: interaction.locale,
})}:`,
value: `[${queue.songs[0].uploader.name}](${queue.songs[0].uploader.url})`,
inline: true,
},
{
name: `${t("music.time", {
ns: "common",
lng: interaction.locale,
})}:`,
value: ` **[${queue.songs[0].formattedDuration}]**`,
inline: false,
}
)
.setImage(
`${
queue.songs[0].thumbnail ||
"https://www.technopat.net/sosyal/data/avatars/o/472/472796.jpg?1648288120"
}`
)
.setColor(config.embed.success)
.setFooter({
text: `${config.footer.text}`,
iconURL: `${config.footer.icon}`,
});
client.distube.setRepeatMode(interaction, 1)
return interaction.reply({embeds: [embed]}).catch((err) => {});
} else if(queue.repeatMode === 1) {
const embed = new EmbedBuilder()
.setTitle(
`${t("succes.songloopoff", {
ns: "common",
lng: interaction.locale,
})}`
)
.setDescription(`**[${queue.songs[0].name}](${queue.songs[0].url})**`)
.addFields(
{
name: `${t("music.author", {
ns: "common",
lng: interaction.locale,
})}:`,
value: `[${queue.songs[0].uploader.name}](${queue.songs[0].uploader.url})`,
inline: true,
},
{
name: `${t("music.time", {
ns: "common",
lng: interaction.locale,
})}:`,
value: ` **[${queue.songs[0].formattedDuration}]**`,
inline: false,
}
)
.setImage(
`${
queue.songs[0].thumbnail ||
"https://www.technopat.net/sosyal/data/avatars/o/472/472796.jpg?1648288120"
}`
)
.setColor(config.embed.error)
.setFooter({
text: `${config.footer.text}`,
iconURL: `${config.footer.icon}`,
});
client.distube.setRepeatMode(interaction, 0)
return interaction.reply({embeds: [embed]}).catch((err) => {});
}
}
});
//Loop Command Play
//Loop Command Skip
client.on("interactionCreate", async (interaction) => {
if (interaction.customId === "loops") {
const queue = client.distube.getQueue(interaction);
if (!queue) return interaction.reply(`${t("error.nosonglist", {
ns: "common",
lng: interaction.locale,
})}`)
let data = await music_mongo.findOne({ guildId: interaction.guild.id });
if (!data) return interaction.reply({content: `${t("error.dataerror", {
ns: "common",
lng: interaction.locale,
})}`, ephemeral: true})
let userr = data.userId
if (interaction.user.id !== userr) return interaction.reply({content: `${t("error.onlyuser", {
ns: "common",
lng: interaction.locale,
})}`, ephemeral: true})
const title = data.title
const author = data.uploader
const time = data.time
const view = data.views
const thumb = data.thumbnail
const url = data.video
const views = view;
function formatNumber(views) {
if (views >= 1000000000) {
return (views / 1000000000).toFixed(1) + "B";
} else if (views >= 1000000) {
return (views / 1000000).toFixed(1) + "M";
} else if (views >= 1000) {
return (views / 1000).toFixed(1) + "K";
}
return views;
}
if (queue.repeatMode === 0) {
const embed = new EmbedBuilder()
.setTitle(
`${t("succes.songloopon", {
ns: "common",
lng: interaction.locale,
})}`
)
.setDescription(`**[${queue.songs[0].name}](${queue.songs[0].url})**`)
.addFields(
{
name: `${t("music.author", {
ns: "common",
lng: interaction.locale,
})}:`,
value: `[${queue.songs[0].uploader.name}](${queue.songs[0].uploader.url})`,
inline: true,
},
{
name: `${t("music.time", {
ns: "common",
lng: interaction.locale,
})}:`,
value: ` **[${queue.songs[0].formattedDuration}]**`,
inline: false,
}
)
.setImage(
`${
queue.songs[0].thumbnail ||
"https://www.technopat.net/sosyal/data/avatars/o/472/472796.jpg?1648288120"
}`
)
.setColor(config.embed.success)
.setFooter({
text: `${config.footer.text}`,
iconURL: `${config.footer.icon}`,
});
client.distube.setRepeatMode(interaction, 1)
return interaction.reply({embeds: [embed]}).catch((err) => {});
} else if(queue.repeatMode === 1) {
const embed = new EmbedBuilder()
.setTitle(
`${t("succes.songloopoff", {
ns: "common",
lng: interaction.locale,
})}`
)
.setDescription(`**[${queue.songs[0].name}](${queue.songs[0].url})**`)
.addFields(
{
name: `${t("music.author", {
ns: "common",
lng: interaction.locale,
})}:`,
value: `[${queue.songs[0].uploader.name}](${queue.songs[0].uploader.url})`,
inline: true,
},
{
name: `${t("music.time", {
ns: "common",
lng: interaction.locale,
})}:`,
value: ` **[${queue.songs[0].formattedDuration}]**`,
inline: false,
}
)
.setImage(
`${
queue.songs[0].thumbnail ||
"https://www.technopat.net/sosyal/data/avatars/o/472/472796.jpg?1648288120"
}`
)
.setColor(config.embed.error)
.setFooter({
text: `${config.footer.text}`,
iconURL: `${config.footer.icon}`,
});
client.distube.setRepeatMode(interaction, 0)
return interaction.reply({embeds: [embed]}).catch((err) => {});
}
}
});
//Loop Command SKip
})();
/* Powered by:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ F a s t - U p t i m e ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
------ Developed by Egehan#7658 ------
https://github.com/egehan0250
https://www.linkedin.com/in/egehan-konta%C5%9F-a91986250
https://stackoverflow.com/users/18989055/egehan
*/