-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathindex.js
More file actions
1315 lines (1118 loc) · 56.1 KB
/
Copy pathindex.js
File metadata and controls
1315 lines (1118 loc) · 56.1 KB
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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// index.js
const { Client, GatewayIntentBits, ActivityType, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ContainerBuilder, SectionBuilder, TextDisplayBuilder, ThumbnailBuilder, SeparatorBuilder, SeparatorSpacingSize, MessageFlags } = require('discord.js');
const { Riffy } = require('riffy');
const config = require('./config.js');
const express = require('express');
require('dotenv').config();
// Function to start Express server
function startExpressServer() {
if (config.express.enabled) {
const app = express();
app.get('/', (req, res) => {
res.json({
status: 'online',
bot: client.user ? client.user.tag : 'Starting...',
servers: client.guilds.cache ? client.guilds.cache.size : 0,
uptime: process.uptime(),
lavalink: isLavalinkConnected ? 'connected' : 'disconnected'
});
});
app.get('/stats', (req, res) => {
res.json({
guilds: client.guilds.cache ? client.guilds.cache.size : 0,
users: client.guilds.cache ? client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0) : 0,
players: riffy.players ? riffy.players.size : 0,
uptime: process.uptime(),
memory: process.memoryUsage().heapUsed / 1024 / 1024,
ping: client.ws ? client.ws.ping : 0,
lavalink: isLavalinkConnected
});
});
app.listen(config.express.port, '0.0.0.0', () => {
console.log(`🌐 Express server running on port ${config.express.port}`);
});
}
}
// Start Express server before bot
startExpressServer();
const intents = [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages
];
if (config.enablePrefix) {
intents.push(GatewayIntentBits.MessageContent);
}
const client = new Client({ intents });
let isLavalinkConnected = false;
const riffy = new Riffy(client, config.lavalink.nodes, {
send: (payload) => {
const guild = client.guilds.cache.get(payload.d.guild_id);
if (guild) guild.shard.send(payload);
},
defaultSearchPlatform: "ytmsearch",
restVersion: "v4"
});
// Fix Riffy Node initialization error by overriding the broken defineProperty call
// This is a workaround for the riffy package bug mentioned in the error
const { Node } = require('riffy/build/structures/Node');
const originalDefineProperty = Object.defineProperty;
Object.defineProperty = function(obj, prop, descriptor) {
if (obj instanceof Node && (prop === 'host' || prop === 'port' || prop === 'password' || prop === 'secure' || prop === 'identifier')) {
return originalDefineProperty(obj, prop, {
value: descriptor.value,
writable: true,
enumerable: true,
configurable: true
});
}
try {
return originalDefineProperty(obj, prop, descriptor);
} catch (e) {
// If it fails with the specific error, try a fallback
if (e instanceof TypeError && e.message.includes('Invalid property descriptor')) {
return originalDefineProperty(obj, prop, {
value: descriptor.value,
writable: true,
enumerable: true,
configurable: true
});
}
throw e;
}
};
const queue247 = new Set();
client.on('ready', async () => {
console.log(`${config.emojis.success} Logged in as ${client.user.tag}`);
try {
riffy.init(client.user.id);
} catch (error) {
console.error(`${config.emojis.error} Failed to initialize Riffy:`, error);
}
const activityTypes = {
'PLAYING': ActivityType.Playing,
'LISTENING': ActivityType.Listening,
'WATCHING': ActivityType.Watching,
'STREAMING': ActivityType.Streaming,
'COMPETING': ActivityType.Competing
};
const activityType = activityTypes[config.activity.type] || ActivityType.Listening;
client.user.setActivity(config.activity.name, { type: activityType });
console.log(`${config.emojis.success} Activity set: ${config.activity.type} ${config.activity.name}`);
const commands = [
{ name: 'play', description: 'Play a song', options: [{ name: 'query', description: 'Song name or URL', type: 3, required: true }] },
{ name: 'pause', description: 'Pause the current song' },
{ name: 'resume', description: 'Resume the paused song' },
{ name: 'skip', description: 'Skip the current song' },
{ name: 'stop', description: 'Stop the player and clear queue' },
{ name: 'volume', description: 'Set volume', options: [{ name: 'level', description: 'Volume level (1-100)', type: 4, required: true, min_value: 1, max_value: 100 }] },
{ name: 'queue', description: 'Show the current queue' },
{ name: 'nowplaying', description: 'Show currently playing song' },
{ name: 'shuffle', description: 'Shuffle the queue' },
{ name: 'loop', description: 'Toggle loop mode', options: [{ name: 'mode', description: 'Loop mode', type: 3, required: true, choices: [{ name: 'Off', value: 'none' }, { name: 'Track', value: 'track' }, { name: 'Queue', value: 'queue' }] }] },
{ name: 'remove', description: 'Remove a song from queue', options: [{ name: 'position', description: 'Position in queue', type: 4, required: true, min_value: 1 }] },
{ name: 'move', description: 'Move a song in queue', options: [{ name: 'from', description: 'From position', type: 4, required: true, min_value: 1 }, { name: 'to', description: 'To position', type: 4, required: true, min_value: 1 }] },
{ name: 'clearqueue', description: 'Clear the queue' },
{ name: '247', description: 'Toggle 24/7 mode' },
{ name: 'stats', description: 'Show bot statistics' },
{ name: 'ping', description: 'Show bot latency' },
{ name: 'invite', description: 'Get bot invite link' },
{ name: 'support', description: 'Get support server link' },
{ name: 'help', description: 'Show all commands' }
];
await client.application.commands.set(commands);
console.log(`${config.emojis.success} Slash commands registered globally`);
});
client.on('raw', (d) => riffy.updateVoiceState(d));
riffy.on('nodeConnect', (node) => {
console.log(`${config.emojis.success} Node ${node.name} connected`);
isLavalinkConnected = true;
});
riffy.on('nodeError', (node, error) => {
console.error(`${config.emojis.error} Node ${node.name} error:`, error);
isLavalinkConnected = false;
});
riffy.on('nodeDisconnect', (node) => {
console.log(`${config.emojis.error} Node ${node.name} disconnected`);
isLavalinkConnected = false;
});
const nowPlayingMessages = new Map();
function formatTime(ms) {
const seconds = Math.floor((ms / 1000) % 60);
const minutes = Math.floor((ms / (1000 * 60)) % 60);
const hours = Math.floor((ms / (1000 * 60 * 60)) % 24);
if (hours > 0) {
return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
}
function createNowPlayingContainer(player, track, disabled = false) {
const info = track.info ?? {};
let thumbnail = info.artworkUrl || info.thumbnail || null;
if (!thumbnail && info.uri && info.uri.includes('youtube.com')) {
const videoId = info.uri.split('v=')[1]?.split('&')[0];
if (videoId) {
thumbnail = `https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`;
}
}
if (!thumbnail && info.uri && info.uri.includes('youtu.be')) {
const videoId = info.uri.split('youtu.be/')[1]?.split('?')[0];
if (videoId) {
thumbnail = `https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`;
}
}
if (!thumbnail) {
thumbnail = 'https://i.imgur.com/QYJfXQv.png';
}
const isPaused = player.paused;
const container = new ContainerBuilder()
.addSectionComponents(
new SectionBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder()
.setContent(`## ${config.emojis.music} Now Playing\n**[${info.title || 'Unknown Title'}](${info.uri || 'https://youtube.com'})**`)
)
.setThumbnailAccessory(
new ThumbnailBuilder()
.setURL(thumbnail)
.setDescription(info.title || 'Song Thumbnail')
)
)
.addTextDisplayComponents(
new TextDisplayBuilder()
.setContent(`**Duration:** ${formatTime(info.length || 0)} • **Requested By:** <@${track.info.requester}>`)
)
.addSeparatorComponents(
new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small).setDivider(true)
)
.addActionRowComponents(
new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(isPaused ? 'resume' : 'pause')
.setEmoji(isPaused ? config.emojis.play : config.emojis.pause)
.setStyle(isPaused ? ButtonStyle.Success : ButtonStyle.Primary)
.setDisabled(disabled),
new ButtonBuilder()
.setCustomId('skip')
.setEmoji(config.emojis.skip)
.setStyle(ButtonStyle.Primary)
.setDisabled(disabled),
new ButtonBuilder()
.setCustomId('stop')
.setEmoji(config.emojis.stop)
.setStyle(ButtonStyle.Danger)
.setDisabled(disabled),
new ButtonBuilder()
.setCustomId('shuffle')
.setEmoji(config.emojis.shuffle)
.setStyle(ButtonStyle.Secondary)
.setDisabled(disabled),
new ButtonBuilder()
.setCustomId('queue')
.setEmoji(config.emojis.queue)
.setStyle(ButtonStyle.Secondary)
.setDisabled(disabled)
)
)
.addActionRowComponents(
new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('loop')
.setEmoji(config.emojis.loop)
.setStyle(player.loop && player.loop !== 'none' ? ButtonStyle.Success : ButtonStyle.Secondary)
.setDisabled(disabled)
)
);
return container;
}
function createSimpleContainer(title, description, emoji = config.emojis.info) {
return new ContainerBuilder()
.addSectionComponents(
new SectionBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder()
.setContent(`## ${emoji} ${title}\n${description}`)
)
.setThumbnailAccessory(
new ThumbnailBuilder()
.setURL(client.user.displayAvatarURL({ size: 1024 }))
.setDescription(title)
)
)
.addSeparatorComponents(
new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small).setDivider(true)
);
}
function createSimpleContainerNoButtons(title, description, emoji = config.emojis.info) {
return new ContainerBuilder()
.addSectionComponents(
new SectionBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder()
.setContent(`## ${emoji} ${title}\n${description}`)
)
.setThumbnailAccessory(
new ThumbnailBuilder()
.setURL(client.user.displayAvatarURL({ size: 1024 }))
.setDescription(title)
)
)
.addSeparatorComponents(
new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small).setDivider(true)
);
}
function createQueueContainer(player, guild, user) {
const queue = player.queue ?? [];
const current = player.current;
let description = '';
if (current?.info) {
description += `**Now Playing:**\n**[${current.info.title}](${current.info.uri})**\n${current.info.author || 'Unknown'} • ${formatTime(current.info.length)} • <@${current.info.requester}>\n\n`;
}
if (queue.length > 0) {
description += `**Up Next:**\n`;
const upcoming = queue.slice(0, 10);
upcoming.forEach((t, i) => {
const inf = t.info || {};
description += `\`${i + 1}.\` **[${inf.title}](${inf.uri})**\n${inf.author || 'Unknown'} • ${formatTime(inf.length || 0)} • <@${t.info.requester}>\n`;
});
if (queue.length > 10) {
description += `\n*...and ${queue.length - 10} more track(s)*`;
}
} else if (!current) {
description = 'The queue is currently empty.';
}
description += `\n\n**Loop:** ${(!player.loop || player.loop === 'none') ? 'off' : player.loop} | **Total:** ${player.queue.length + 1} tracks`;
let thumbnail = client.user.displayAvatarURL({ size: 1024 });
return new ContainerBuilder()
.addSectionComponents(
new SectionBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder()
.setContent(`## ${config.emojis.queue} Queue\n${description}`)
)
.setThumbnailAccessory(
new ThumbnailBuilder()
.setURL(thumbnail)
.setDescription('Queue')
)
)
.addSeparatorComponents(
new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small).setDivider(true)
);
}
function createStatsContainer() {
const uptime = formatTime(client.uptime);
const players = riffy.players.size;
const totalUsers = client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0);
const memory = (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2);
const description = `**Servers:** ${client.guilds.cache.size}\n**Users:** ${totalUsers}\n**Players:** ${players}\n**Uptime:** ${uptime}\n**Ping:** ${client.ws.ping}ms\n**Memory:** ${memory} MB`;
return new ContainerBuilder()
.addSectionComponents(
new SectionBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder()
.setContent(`## ${config.emojis.info} Bot Statistics\n${description}`)
)
.setThumbnailAccessory(
new ThumbnailBuilder()
.setURL(client.user.displayAvatarURL({ size: 1024 }))
.setDescription('Bot Avatar')
)
)
.addSeparatorComponents(
new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small).setDivider(true)
);
}
function createHelpContainer() {
const lavalinkStatus = isLavalinkConnected ? '🟢 Connected' : '🔴 Not Connected';
const description = `A powerful music bot with high quality audio\n\n**Total Commands:** 17\n**Prefix:** \`${config.prefix}\`\n**Lavalink:** ${lavalinkStatus}\nMade by **Unknownz**\n\n**${config.emojis.music} Music Commands**\n**play** (p) - Play a song\n**pause** (pa) - Pause current song\n**resume** (r, res) - Resume playback\n**skip** (s, next) - Skip current song\n**stop** (st, leave) - Stop player\n**nowplaying** (np) - Show current song\n**queue** (q) - Show queue\n**loop** (l, repeat) - Loop mode\n**shuffle** (sh, mix) - Shuffle queue\n**volume** (v, vol) - Set volume\n**clearqueue** (cq, clear) - Clear queue\n**remove** (rm, delete) - Remove from queue\n**move** (mv) - Move in queue\n**247** (24/7, stay) - Toggle 24/7\n\n**${config.emojis.info} Utility Commands**\n**stats** (status, info) - Bot stats\n**ping** (latency) - Bot ping\n**invite** (inv) - Invite link\n**support** (server) - Support server\n**help** (h, cmd) - This message`;
return new ContainerBuilder()
.addSectionComponents(
new SectionBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder()
.setContent(`## ${client.user.username} Help\n${description}`)
)
.setThumbnailAccessory(
new ThumbnailBuilder()
.setURL(client.user.displayAvatarURL({ size: 1024 }))
.setDescription('Bot Avatar')
)
)
.addSeparatorComponents(
new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small).setDivider(true)
)
.addActionRowComponents(
new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('Invite Me')
.setStyle(ButtonStyle.Link)
.setURL(`https://discord.com/api/oauth2/authorize?client_id=${client.user.id}&permissions=3165184&scope=bot%20applications.commands`),
new ButtonBuilder()
.setLabel('Support')
.setStyle(ButtonStyle.Link)
.setURL(config.supportServer)
)
);
}
riffy.on('trackStart', async (player, track) => {
const channel = client.channels.cache.get(player.textChannel);
if (!channel) return;
const container = createNowPlayingContainer(player, track);
try {
const msg = await channel.send({ components: [container], flags: MessageFlags.IsPersistent | MessageFlags.IsComponentsV2 });
nowPlayingMessages.set(player.guildId, msg);
} catch (err) {
console.error('Failed to send Now Playing message:', err);
}
});
riffy.on('queueEnd', async (player) => {
const channel = client.channels.cache.get(player.textChannel);
const msg = nowPlayingMessages.get(player.guildId);
if (msg && player.current) {
try {
const disabledContainer = createNowPlayingContainer(player, player.current, true);
await msg.edit({ components: [disabledContainer], flags: MessageFlags.IsPersistent | MessageFlags.IsComponentsV2 });
} catch (error) {
console.error('Failed to disable buttons:', error);
}
nowPlayingMessages.delete(player.guildId);
}
if (queue247.has(player.guildId)) {
if (channel) {
const container = createSimpleContainerNoButtons('24/7 Mode', 'Queue ended but staying in 24/7 mode', config.emojis.info);
await channel.send({ components: [container], flags: MessageFlags.IsPersistent | MessageFlags.IsComponentsV2 });
}
return;
}
if (channel) {
const container = createSimpleContainerNoButtons('Queue Ended', 'Queue ended, leaving voice channel', config.emojis.success);
await channel.send({ components: [container], flags: MessageFlags.IsPersistent | MessageFlags.IsComponentsV2 });
}
player.destroy();
});
client.on('interactionCreate', async (interaction) => {
if (interaction.isButton()) {
const player = riffy.players.get(interaction.guildId);
if (!player) {
return interaction.reply({ content: `${config.emojis.error} No player found`, ephemeral: true });
}
const member = interaction.member;
if (!member.voice.channel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in a voice channel`, ephemeral: true });
}
if (member.voice.channel.id !== player.voiceChannel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in the same voice channel`, ephemeral: true });
}
switch (interaction.customId) {
case 'pause':
case 'resume': {
const message = nowPlayingMessages.get(player.guildId);
const shouldPause = interaction.customId === 'pause';
await player.pause(shouldPause);
if (message && player.current) {
const updatedContainer = createNowPlayingContainer(player, player.current);
await message.edit({ components: [updatedContainer], flags: MessageFlags.IsPersistent | MessageFlags.IsComponentsV2 }).catch(() => {});
}
await interaction.reply({
content: shouldPause ? `${config.emojis.pause} Paused` : `${config.emojis.play} Resumed`,
ephemeral: true
});
break;
}
case 'skip': {
player.stop();
const disabledContainer = createNowPlayingContainer(player, player.current, true);
await interaction.message.edit({ components: [disabledContainer], flags: MessageFlags.IsPersistent | MessageFlags.IsComponentsV2 });
await interaction.reply({ content: `${config.emojis.skip} Skipped`, ephemeral: true });
break;
}
case 'stop': {
const disabledContainer = createNowPlayingContainer(player, player.current, true);
await interaction.message.edit({ components: [disabledContainer], flags: MessageFlags.IsPersistent | MessageFlags.IsComponentsV2 });
player.destroy();
await interaction.reply({ content: `${config.emojis.stop} Stopped`, ephemeral: true });
break;
}
case 'shuffle': {
if (player.queue.length === 0) {
return interaction.reply({ content: `${config.emojis.error} Queue is empty`, ephemeral: true });
}
player.queue.shuffle();
await interaction.reply({ content: `${config.emojis.shuffle} Shuffled queue`, ephemeral: true });
break;
}
case 'loop': {
const modes = ['none', 'track', 'queue'];
const currentMode = player.loop || 'none';
const nextMode = modes[(modes.indexOf(currentMode) + 1) % modes.length];
player.setLoop(nextMode);
const loopLabel = nextMode === 'none' ? 'off' : nextMode;
const loopMsg = nowPlayingMessages.get(player.guildId);
if (loopMsg && player.current) {
const updatedContainer = createNowPlayingContainer(player, player.current);
await loopMsg.edit({ components: [updatedContainer], flags: MessageFlags.IsPersistent | MessageFlags.IsComponentsV2 }).catch(() => {});
}
await interaction.reply({ content: `${config.emojis.loop} Loop set to: ${loopLabel}`, ephemeral: true });
break;
}
case 'queue': {
const queueContainer = createQueueContainer(player, interaction.guild, interaction.user);
await interaction.reply({ components: [queueContainer], flags: MessageFlags.IsComponentsV2, ephemeral: true });
break;
}
}
}
if (!interaction.isChatInputCommand()) return;
const { commandName, options, member, guild, channel } = interaction;
if (commandName === 'play') {
const query = options.getString('query');
if (!member.voice.channel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in a voice channel`, ephemeral: true });
}
if (!isLavalinkConnected) {
return interaction.reply({ content: `${config.emojis.error} Lavalink is not connected. Music commands are unavailable.`, ephemeral: true });
}
await interaction.deferReply();
try {
let player = riffy.players.get(guild.id);
if (!player) {
player = riffy.createConnection({
guildId: guild.id,
voiceChannel: member.voice.channel.id,
textChannel: channel.id,
deaf: true
});
}
const resolve = await riffy.resolve({ query, requester: member.user.id });
if (!resolve || !resolve.tracks.length) {
return interaction.editReply({ content: `${config.emojis.error} No results found` });
}
if (resolve.loadType === 'playlist') {
for (const track of resolve.tracks) {
track.info.requester = member.user.id;
player.queue.add(track);
}
const container = createSimpleContainerNoButtons(
'Playlist Added',
`Added playlist **${resolve.playlistInfo.name}** (${resolve.tracks.length} tracks)`,
config.emojis.success
);
await interaction.editReply({ components: [container], flags: MessageFlags.IsPersistent | MessageFlags.IsComponentsV2 });
} else if (resolve.loadType === 'search' || resolve.loadType === 'track') {
const track = resolve.tracks[0];
track.info.requester = member.user.id;
player.queue.add(track);
const container = createSimpleContainerNoButtons(
'Added to Queue',
`[${track.info.title}](${track.info.uri})`,
config.emojis.success
);
await interaction.editReply({ components: [container], flags: MessageFlags.IsPersistent | MessageFlags.IsComponentsV2 });
} else {
return interaction.editReply({ content: `${config.emojis.error} No results found` });
}
if (!player.playing && !player.paused) player.play();
} catch (error) {
console.error('Play command error:', error);
await interaction.editReply({ content: `${config.emojis.error} An error occurred while playing the song` });
}
}
if (commandName === 'pause') {
const player = riffy.players.get(guild.id);
if (!player) return interaction.reply({ content: `${config.emojis.error} No player found`, ephemeral: true });
if (!member.voice.channel || member.voice.channel.id !== player.voiceChannel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in the same voice channel`, ephemeral: true });
}
player.pause(true);
const container = createSimpleContainer('Paused', 'Playback paused', config.emojis.pause);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'resume') {
const player = riffy.players.get(guild.id);
if (!player) return interaction.reply({ content: `${config.emojis.error} No player found`, ephemeral: true });
if (!member.voice.channel || member.voice.channel.id !== player.voiceChannel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in the same voice channel`, ephemeral: true });
}
player.pause(false);
const container = createSimpleContainer('Resumed', 'Playback resumed', config.emojis.play);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'skip') {
const player = riffy.players.get(guild.id);
if (!player) return interaction.reply({ content: `${config.emojis.error} No player found`, ephemeral: true });
if (!member.voice.channel || member.voice.channel.id !== player.voiceChannel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in the same voice channel`, ephemeral: true });
}
player.stop();
const container = createSimpleContainer('Skipped', 'Skipped to next track', config.emojis.skip);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'stop') {
const player = riffy.players.get(guild.id);
if (!player) return interaction.reply({ content: `${config.emojis.error} No player found`, ephemeral: true });
if (!member.voice.channel || member.voice.channel.id !== player.voiceChannel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in the same voice channel`, ephemeral: true });
}
player.destroy();
const container = createSimpleContainer('Stopped', 'Stopped and cleared queue', config.emojis.stop);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'volume') {
const player = riffy.players.get(guild.id);
if (!player) return interaction.reply({ content: `${config.emojis.error} No player found`, ephemeral: true });
if (!member.voice.channel || member.voice.channel.id !== player.voiceChannel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in the same voice channel`, ephemeral: true });
}
const volume = options.getInteger('level');
player.setVolume(volume);
const container = createSimpleContainer('Volume Set', `Volume set to ${volume}%`, config.emojis.volume);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'queue') {
const player = riffy.players.get(guild.id);
if (!player) return interaction.reply({ content: `${config.emojis.error} No player found`, ephemeral: true });
if (player.queue.length === 0 && !player.current) {
return interaction.reply({ content: `${config.emojis.error} Queue is empty`, ephemeral: true });
}
const queueContainer = createQueueContainer(player, guild, interaction.user);
await interaction.reply({ components: [queueContainer], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'nowplaying') {
const player = riffy.players.get(guild.id);
if (!player || !player.current) {
return interaction.reply({ content: `${config.emojis.error} Nothing is playing`, ephemeral: true });
}
const info = player.current.info ?? {};
let thumbnail = info.artworkUrl || info.thumbnail || null;
if (!thumbnail && info.uri && info.uri.includes('youtube.com')) {
const videoId = info.uri.split('v=')[1]?.split('&')[0];
if (videoId) {
thumbnail = `https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`;
}
}
if (!thumbnail && info.uri && info.uri.includes('youtu.be')) {
const videoId = info.uri.split('youtu.be/')[1]?.split('?')[0];
if (videoId) {
thumbnail = `https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`;
}
}
if (!thumbnail) {
thumbnail = 'https://i.imgur.com/QYJfXQv.png';
}
const currentPosition = player.position || 0;
const totalDuration = info.length || 0;
const status = player.paused ? '⏸️ Paused' : '▶️ Playing';
const description = `**[${info.title || 'Unknown Title'}](${info.uri || 'https://youtube.com'})**\n\n**Status:** ${status}\n**Current Duration:** ${formatTime(currentPosition)} / ${formatTime(totalDuration)}\n**Requested By:** <@${player.current.info.requester}>\n**Loop:** ${(!player.loop || player.loop === 'none') ? 'off' : player.loop}`;
const container = new ContainerBuilder()
.addSectionComponents(
new SectionBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder()
.setContent(`## ${config.emojis.music} Now Playing\n${description}`)
)
.setThumbnailAccessory(
new ThumbnailBuilder()
.setURL(thumbnail)
.setDescription(info.title || 'Song Thumbnail')
)
)
.addSeparatorComponents(
new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small).setDivider(true)
);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'shuffle') {
const player = riffy.players.get(guild.id);
if (!player) return interaction.reply({ content: `${config.emojis.error} No player found`, ephemeral: true });
if (!member.voice.channel || member.voice.channel.id !== player.voiceChannel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in the same voice channel`, ephemeral: true });
}
if (player.queue.length === 0) {
return interaction.reply({ content: `${config.emojis.error} Queue is empty`, ephemeral: true });
}
player.queue.shuffle();
const container = createSimpleContainer('Shuffled', 'Shuffled the queue', config.emojis.shuffle);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'loop') {
const player = riffy.players.get(guild.id);
if (!player) return interaction.reply({ content: `${config.emojis.error} No player found`, ephemeral: true });
if (!member.voice.channel || member.voice.channel.id !== player.voiceChannel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in the same voice channel`, ephemeral: true });
}
const mode = options.getString('mode');
player.setLoop(mode);
const container = createSimpleContainer('Loop Set', `Loop set to: ${mode}`, config.emojis.loop);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'remove') {
const player = riffy.players.get(guild.id);
if (!player) return interaction.reply({ content: `${config.emojis.error} No player found`, ephemeral: true });
if (!member.voice.channel || member.voice.channel.id !== player.voiceChannel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in the same voice channel`, ephemeral: true });
}
const position = options.getInteger('position') - 1;
if (position < 0 || position >= player.queue.length) {
return interaction.reply({ content: `${config.emojis.error} Invalid position`, ephemeral: true });
}
const removed = player.queue.remove(position);
const container = createSimpleContainer('Removed', `Removed: ${removed.info.title}`, config.emojis.success);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'move') {
const player = riffy.players.get(guild.id);
if (!player) return interaction.reply({ content: `${config.emojis.error} No player found`, ephemeral: true });
if (!member.voice.channel || member.voice.channel.id !== player.voiceChannel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in the same voice channel`, ephemeral: true });
}
const from = options.getInteger('from') - 1;
const to = options.getInteger('to') - 1;
if (from < 0 || from >= player.queue.length || to < 0 || to >= player.queue.length) {
return interaction.reply({ content: `${config.emojis.error} Invalid positions`, ephemeral: true });
}
const track = player.queue.remove(from);
player.queue.splice(to, 0, track);
const container = createSimpleContainer('Moved', `Moved: ${track.info.title}`, config.emojis.success);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'clearqueue') {
const player = riffy.players.get(guild.id);
if (!player) return interaction.reply({ content: `${config.emojis.error} No player found`, ephemeral: true });
if (!member.voice.channel || member.voice.channel.id !== player.voiceChannel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in the same voice channel`, ephemeral: true });
}
player.queue.clear();
const container = createSimpleContainer('Queue Cleared', 'Cleared the queue', config.emojis.success);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === '247') {
const player = riffy.players.get(guild.id);
if (!member.voice.channel) {
return interaction.reply({ content: `${config.emojis.error} You need to be in a voice channel`, ephemeral: true });
}
if (queue247.has(guild.id)) {
queue247.delete(guild.id);
const container = createSimpleContainer('24/7 Disabled', '24/7 mode disabled', config.emojis.success);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
} else {
queue247.add(guild.id);
if (!player) {
riffy.createConnection({
guildId: guild.id,
voiceChannel: member.voice.channel.id,
textChannel: channel.id,
deaf: true
});
}
const container = createSimpleContainer('24/7 Enabled', '24/7 mode enabled', config.emojis.success);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
}
if (commandName === 'stats') {
const statsContainer = createStatsContainer();
await interaction.reply({ components: [statsContainer], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'ping') {
const container = createSimpleContainer('Pong!', `Latency: ${client.ws.ping}ms`, config.emojis.info);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'invite') {
const invite = `https://discord.com/api/oauth2/authorize?client_id=${client.user.id}&permissions=3165184&scope=bot%20applications.commands`;
const container = new ContainerBuilder()
.addSectionComponents(
new SectionBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder()
.setContent(`## ${config.emojis.success} Invite Bot\n[Click here to invite me](${invite})`)
)
.setThumbnailAccessory(
new ThumbnailBuilder()
.setURL(client.user.displayAvatarURL({ size: 1024 }))
.setDescription('Invite Bot')
)
)
.addSeparatorComponents(
new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small).setDivider(true)
)
.addActionRowComponents(
new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('Invite Me')
.setStyle(ButtonStyle.Link)
.setURL(invite)
)
);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'support') {
const container = new ContainerBuilder()
.addSectionComponents(
new SectionBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder()
.setContent(`## ${config.emojis.info} Support Server\n[Join our support server](${config.supportServer})`)
)
.setThumbnailAccessory(
new ThumbnailBuilder()
.setURL(client.user.displayAvatarURL({ size: 1024 }))
.setDescription('Support Server')
)
)
.addSeparatorComponents(
new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small).setDivider(true)
)
.addActionRowComponents(
new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('Support')
.setStyle(ButtonStyle.Link)
.setURL(config.supportServer)
)
);
await interaction.reply({ components: [container], flags: MessageFlags.IsComponentsV2 });
}
if (commandName === 'help') {
const helpContainer = createHelpContainer();
await interaction.reply({ components: [helpContainer], flags: MessageFlags.IsComponentsV2 });
}
});
if (config.enablePrefix) {
client.on('messageCreate', async (message) => {
if (message.author.bot || !message.guild) return;
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/);
let command = args.shift().toLowerCase();
for (const [cmd, aliases] of Object.entries(config.aliases)) {
if (aliases.includes(command)) {
command = cmd;
break;
}
}
if (command === 'play') {
const query = args.join(' ');
if (!query) return message.reply(`${config.emojis.error} Please provide a song name or URL`);
if (!message.member.voice.channel) {
return message.reply(`${config.emojis.error} You need to be in a voice channel`);
}
if (!isLavalinkConnected) {
return message.reply(`${config.emojis.error} Lavalink is not connected. Music commands are unavailable.`);
}
try {
let player = riffy.players.get(message.guild.id);
if (!player) {
player = riffy.createConnection({
guildId: message.guild.id,
voiceChannel: message.member.voice.channel.id,
textChannel: message.channel.id,
deaf: true
});
}
const resolve = await riffy.resolve({ query, requester: message.author.id });
if (!resolve || !resolve.tracks.length) {
return message.reply(`${config.emojis.error} No results found`);
}
if (resolve.loadType === 'playlist') {
for (const track of resolve.tracks) {
track.info.requester = message.author.id;
player.queue.add(track);
}
const container = createSimpleContainerNoButtons(
'Playlist Added',
`Added playlist **${resolve.playlistInfo.name}** (${resolve.tracks.length} tracks)`,
config.emojis.success
);
await message.reply({ components: [container], flags: MessageFlags.IsPersistent | MessageFlags.IsComponentsV2 });
} else if (resolve.loadType === 'search' || resolve.loadType === 'track') {
const track = resolve.tracks[0];
track.info.requester = message.author.id;
player.queue.add(track);
const container = createSimpleContainerNoButtons(
'Added to Queue',
`[${track.info.title}](${track.info.uri})`,
config.emojis.success
);
await message.reply({ components: [container], flags: MessageFlags.IsPersistent | MessageFlags.IsComponentsV2 });
} else {
return message.reply(`${config.emojis.error} No results found`);
}
if (!player.playing && !player.paused) player.play();
} catch (error) {
console.error('Play command error:', error);
await message.reply(`${config.emojis.error} An error occurred while playing the song`);
}
}
if (command === 'pause') {
const player = riffy.players.get(message.guild.id);
if (!player) return message.reply(`${config.emojis.error} No player found`);