-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
2451 lines (2225 loc) · 107 KB
/
index.js
File metadata and controls
2451 lines (2225 loc) · 107 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
// Discord Variables
const { Client, GatewayIntentBits, Partials, EmbedBuilder, AuditLogEvent, ActionRowBuilder, ButtonBuilder, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle, InteractionType, PermissionsBitField } = require('discord.js');
var prefix = "!";
require('dotenv').config();
// Discord Intents
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildMessageReactions,
],
partials: [
Partials.GuildMember
]
});
// Quick Database
bot.db = require('quick.db');
// Chat GPT
const openai = require("../bot/utils/openAi");
// Separate all Command files from an array.
bot.commands = new Map()
// Discord Music player
const { Player } = require('discord-player');
// Discord player settings
bot.player = new Player(bot, {
leaveOnEnd: false,
leaveOnStop: false,
leaveOnEmpty: true,
leaveOnEndCooldown: 1000,
leaveOnEmptyCooldown: 1000,
autoSelfDeaf: true, // This doesn't really matter. It's just a prefrence to make the bot look like it can't hear.
ytdlOptions: {
quality: "highest", // Keep this as highest as it will make the music play 99% better.
filter: "audioonly", // Only play audio files we don't need videos.
highWaterMark: 1 << 25,
dlChunkSize: 0,
},
initialVolume: 100,
bufferingTimeout: 30,
spotifyBridge: true, // Tap into spotify to play music without needing to be logged in.
disableVolume: false, // Don't make this true. If you do the bot will look like it is playing but there won't be sound.
volumeSmoothness: 0.08 // Adjust this to make it as smooth as you want to your liking.
})
// Roblox Variables
const rbxbot = require('noblox.js');
// Syncronously read content from files
const { readdirSync } = require('fs');
// Express Webserver
const express = require('express');
const app = express();
const port = 80;
const axios = require('axios');
const bodyParser = require('body-parser');
// Custom console logging
const pogger = require('pogger');
const colors = require('colors');
// Milliseconds converter
const ms = require('ms');
const Time = ms('5m');
bot.slashcommands = []
// Turn all slash commands into an array so we can iterate over each one at a time.
const commands = readdirSync('./Commands').filter(file =>
file.endsWith('.js')
)
// Find all command files that end in .js for Javascript files only. Change this to whatever code language you are making the bot in.
for (command of commands) {
const file = require(`./Commands/${command}`)
bot.commands.set(file.name.toLowerCase(), file)
if (file.data) {
bot.slashcommands.push(file.data)
}
}
// Removes case sensitivity of the files by always returning the name as lowercase and pushes the slash commands into the array.
const events = readdirSync('./Events')
// Reads our Events folder with the files for event functions.
for (const event of events) {
const file = require(`./Events/${event}`)
const name = event.split('.')[0]
bot.on(name, file.execute.bind(null, bot))
}
// Executes our Event files.
// Beginning of Bot code!
bot.on('ready', async() => {
// Bot is logged in and ready to run commands.
// Anti-Spam
const usersMap = new Map();
const LIMIT = 5;
const DIFF = 120000; //milliseconds
bot.on('messageCreate', async (message) => {
if (message.author.id === bot.user.id) return;
try {
if(usersMap.has(message.author.id)) {
const userData = usersMap.get(message.author.id);
const { lastMessage, timer } = userData;
const difference = message.createdTimestamp - lastMessage.createdTimestamp;
let msgCount = userData.msgCount;
let attempts = bot.db.get(`attempts_${message.guild.id}_${message.author.id}`);
if(difference > DIFF) {
clearTimeout(timer);
console.log('Cleared Timeout');
userData.msgCount = 1;
userData.lastMessage = message;
userData.timer = setTimeout(() => {
usersMap.delete(message.author.id)
console.log('Removed from map.')
}, 5000);
usersMap.set(message.author.id, userData)
} else {
++msgCount;
let reason = "[AutoMod] Spamming isn't allowed!";
let member = message.guild.members.cache.get(message.author.id);
if (message.member.permissions.has('ModerateMembers' || 'BanMembers' || 'KickMembers' || 'Administrator')) return;
if (attempts <= 3 && member.moderatable && parseInt(msgCount) === LIMIT) {
bot.db.add(`attempts_${message.guild.id}_${message.author.id}`, 1);
bot.db.set(`userWarnings_${message.guild.id}_${message.author.id}.userid`, message.author.id);
bot.db.add(`userWarnings_${message.guild.id}_${message.author.id}.warnings`, 1);
bot.db.push(`userWarnings_${message.guild.id}_${message.author.id}.reasons`, reason);
let embed = new EmbedBuilder()
.setColor("Yellow")
.setTitle(`**Moderation Report**`)
.setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL()})
.setFooter({ text: `${bot.user.username} | This message will Auto-Delete in 5 seconds!`, iconURL: bot.user.displayAvatarURL() })
.addFields(
{
name: '**Username:**',
value: `${message.author.username}`,
inline: true
},
{
name: '**Discriminator:**',
value: `${message.author.discriminator}`,
inline: true
},
{
name: '**User Tag:**',
value: `${message.author.tag}`,
inline: true
},
{
name: '**User Mention:**',
value: `${message.author}`,
inline: true
},
{
name: '**UserId:**',
value: `${message.author.id}`,
inline: true
},
{
name: '**Moderation Type:**',
value: 'Warn',
inline: true
},
{
name: '**Reason:**',
value: `${reason}`,
inline: true
},
{
name: '**Moderator:**',
value: `${bot.user.username}`,
inline: true
}
)
.setTimestamp(Date.now());
// Fetch the spamming user's messages and bulk delete them
message.channel.messages.fetch({ limit: LIMIT }).then(messages => {
const userMessages = messages.filter(msg => msg.author.id === message.author.id);
Promise.all([
message.channel.bulkDelete(userMessages).catch(console.error),
message.channel.send({ embeds: [embed] }).then(msg => {
setTimeout(() => {
msg.delete().catch(() => {
return;
});
}, 5000);
})
])
}).catch(console.error)
} else if (attempts == 4 && member.moderatable && parseInt(msgCount) === LIMIT) {
bot.db.add(`attempts_${message.guild.id}_${message.author.id}`, 1);
reason = "[AutoMod] Timed out for Spamming! Duration: 1 Minute!"
let embed = new EmbedBuilder()
.setColor("Red")
.setTitle(`**Moderation Report**`)
.setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL()})
.setFooter({ text: `${bot.user.username} | This message will Auto-Delete in 5 seconds!`, iconURL: bot.user.displayAvatarURL() })
.addFields(
{
name: '**Username:**',
value: `${message.author.username}`,
inline: true
},
{
name: '**Discriminator:**',
value: `${message.author.discriminator}`,
inline: true
},
{
name: '**User Tag:**',
value: `${message.author.tag}`,
inline: true
},
{
name: '**User Mention:**',
value: `${message.author}`,
inline: true
},
{
name: '**UserId:**',
value: `${message.author.id}`,
inline: true
},
{
name: '**Moderation Type:**',
value: 'Timeout',
inline: true
},
{
name: '**Reason:**',
value: `${reason}`,
inline: true
},
{
name: '**Moderator:**',
value: `${bot.user.username}`,
inline: true
}
)
.setTimestamp(Date.now());
// Fetch the spamming user's messages and bulk delete them
message.channel.messages.fetch({ limit: LIMIT }).then(messages => {
const userMessages = messages.filter(msg => msg.author.id === message.author.id);
Promise.all([
member.timeout(60000, reason),
message.channel.bulkDelete(userMessages).catch(console.error),
message.channel.send({ embeds: [embed] }).then(msg => {
setTimeout(() => {
msg.delete().catch(() => {
return;
})
}, 5000)
})
])
}).catch(console.error);
} else if (attempts == 5 && member.moderatable && parseInt(msgCount) === LIMIT) {
bot.db.add(`attempts_${message.guild.id}_${message.author.id}`, 1);
reason = "[AutoMod] Timed out for Spamming! Duration: 5 Minutes!"
let embed = new EmbedBuilder()
.setColor("Red")
.setTitle(`**Moderation Report**`)
.setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL()})
.setFooter({ text: `${bot.user.username} | This message will Auto-Delete in 5 seconds!`, iconURL: bot.user.displayAvatarURL() })
.addFields(
{
name: '**Username:**',
value: `${message.author.username}`,
inline: true
},
{
name: '**Discriminator:**',
value: `${message.author.discriminator}`,
inline: true
},
{
name: '**User Tag:**',
value: `${message.author.tag}`,
inline: true
},
{
name: '**User Mention:**',
value: `${message.author}`,
inline: true
},
{
name: '**UserId:**',
value: `${message.author.id}`,
inline: true
},
{
name: '**Moderation Type:**',
value: 'Timeout',
inline: true
},
{
name: '**Reason:**',
value: `${reason}`,
inline: true
},
{
name: '**Moderator:**',
value: `${bot.user.username}`,
inline: true
}
)
.setTimestamp(Date.now());
// Fetch the spamming user's messages and bulk delete them
message.channel.messages.fetch({ limit: LIMIT }).then(messages => {
const userMessages = messages.filter(msg => msg.author.id === message.author.id);
Promise.all([
member.timeout(300000, reason),
message.channel.bulkDelete(userMessages).catch(console.error),
message.channel.send({ embeds: [embed] }).then(msg => {
setTimeout(() => {
msg.delete().catch(() => {
return;
})
}, 5000)
})
])
}).catch(console.error);
} else if (attempts == 6 && member.moderatable && parseInt(msgCount) === LIMIT) {
bot.db.add(`attempts_${message.guild.id}_${message.author.id}`, 1);
reason = "[AutoMod] Timed out for Spamming! Duration: 10 Minutes!"
let embed = new EmbedBuilder()
.setColor("Red")
.setTitle(`**Moderation Report**`)
.setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL()})
.setFooter({ text: `${bot.user.username} | This message will Auto-Delete in 5 seconds!`, iconURL: bot.user.displayAvatarURL() })
.addFields(
{
name: '**Username:**',
value: `${message.author.username}`,
inline: true
},
{
name: '**Discriminator:**',
value: `${message.author.discriminator}`,
inline: true
},
{
name: '**User Tag:**',
value: `${message.author.tag}`,
inline: true
},
{
name: '**User Mention:**',
value: `${message.author}`,
inline: true
},
{
name: '**UserId:**',
value: `${message.author.id}`,
inline: true
},
{
name: '**Moderation Type:**',
value: 'Timeout',
inline: true
},
{
name: '**Reason:**',
value: `${reason}`,
inline: true
},
{
name: '**Moderator:**',
value: `${bot.user.username}`,
inline: true
}
)
.setTimestamp(Date.now());
// Fetch the spamming user's messages and bulk delete them
message.channel.messages.fetch({ limit: LIMIT }).then(messages => {
const userMessages = messages.filter(msg => msg.author.id === message.author.id);
Promise.all([
member.timeout(600000, reason),
message.channel.bulkDelete(userMessages).catch(console.error),
message.channel.send({ embeds: [embed] }).then(msg => {
setTimeout(() => {
msg.delete().catch(() => {
return;
})
}, 5000)
})
])
}).catch(console.error);
} else if (attempts == 7 && member.moderatable && parseInt(msgCount) === LIMIT) {
bot.db.add(`attempts_${message.guild.id}_${message.author.id}`, 1);
reason = "[AutoMod] Timed out for Spamming! Duration: 1 Hour!"
let embed = new EmbedBuilder()
.setColor("Red")
.setTitle(`**Moderation Report**`)
.setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL()})
.setFooter({ text: `${bot.user.username} | This message will Auto-Delete in 5 seconds!`, iconURL: bot.user.displayAvatarURL() })
.addFields(
{
name: '**Username:**',
value: `${message.author.username}`,
inline: true
},
{
name: '**Discriminator:**',
value: `${message.author.discriminator}`,
inline: true
},
{
name: '**User Tag:**',
value: `${message.author.tag}`,
inline: true
},
{
name: '**User Mention:**',
value: `${message.author}`,
inline: true
},
{
name: '**UserId:**',
value: `${message.author.id}`,
inline: true
},
{
name: '**Moderation Type:**',
value: 'Timeout',
inline: true
},
{
name: '**Reason:**',
value: `${reason}`,
inline: true
},
{
name: '**Moderator:**',
value: `${bot.user.username}`,
inline: true
}
)
.setTimestamp(Date.now());
// Fetch the spamming user's messages and bulk delete them
message.channel.messages.fetch({ limit: LIMIT }).then(messages => {
const userMessages = messages.filter(msg => msg.author.id === message.author.id);
Promise.all([
member.timeout(3600000, reason),
message.channel.bulkDelete(userMessages).catch(console.error),
message.channel.send({ embeds: [embed] }).then(msg => {
setTimeout(() => {
msg.delete().catch(() => {
return;
})
}, 5000)
})
])
}).catch(console.error);
} else if (attempts == 8 && member.moderatable && parseInt(msgCount) === LIMIT) {
bot.db.add(`attempts_${message.guild.id}_${message.author.id}`, 1);
reason = "[AutoMod] Timed out for Spamming! Duration: 1 Day!"
let embed = new EmbedBuilder()
.setColor("Red")
.setTitle(`**Moderation Report**`)
.setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL()})
.setFooter({ text: `${bot.user.username} | This message will Auto-Delete in 5 seconds!`, iconURL: bot.user.displayAvatarURL() })
.addFields(
{
name: '**Username:**',
value: `${message.author.username}`,
inline: true
},
{
name: '**Discriminator:**',
value: `${message.author.discriminator}`,
inline: true
},
{
name: '**User Tag:**',
value: `${message.author.tag}`,
inline: true
},
{
name: '**User Mention:**',
value: `${message.author}`,
inline: true
},
{
name: '**UserId:**',
value: `${message.author.id}`,
inline: true
},
{
name: '**Moderation Type:**',
value: 'Timeout',
inline: true
},
{
name: '**Reason:**',
value: `${reason}`,
inline: true
},
{
name: '**Moderator:**',
value: `${bot.user.username}`,
inline: true
}
)
.setTimestamp(Date.now());
// Fetch the spamming user's messages and bulk delete them
message.channel.messages.fetch({ limit: LIMIT }).then(messages => {
const userMessages = messages.filter(msg => msg.author.id === message.author.id);
Promise.all([
member.timeout(86400000, reason),
message.channel.bulkDelete(userMessages).catch(console.error),
message.channel.send({ embeds: [embed] }).then(msg => {
setTimeout(() => {
msg.delete().catch(() => {
return;
})
}, 5000)
})
])
}).catch(console.error);
} else if (attempts == 9 && member.moderatable && parseInt(msgCount) === LIMIT) {
bot.db.add(`attempts_${message.guild.id}_${message.author.id}`, 1);
reason = "[AutoMod] Timed out for Spamming! Duration: 1 Week!"
let embed = new EmbedBuilder()
.setColor("Red")
.setTitle(`**Moderation Report**`)
.setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL()})
.setFooter({ text: `${bot.user.username} | This message will Auto-Delete in 5 seconds!`, iconURL: bot.user.displayAvatarURL() })
.addFields(
{
name: '**Username:**',
value: `${message.author.username}`,
inline: true
},
{
name: '**Discriminator:**',
value: `${message.author.discriminator}`,
inline: true
},
{
name: '**User Tag:**',
value: `${message.author.tag}`,
inline: true
},
{
name: '**User Mention:**',
value: `${message.author}`,
inline: true
},
{
name: '**UserId:**',
value: `${message.author.id}`,
inline: true
},
{
name: '**Moderation Type:**',
value: 'Timeout',
inline: true
},
{
name: '**Reason:**',
value: `${reason}`,
inline: true
},
{
name: '**Moderator:**',
value: `${bot.user.username}`,
inline: true
}
)
.setTimestamp(Date.now());
// Fetch the spamming user's messages and bulk delete them
message.channel.messages.fetch({ limit: LIMIT }).then(messages => {
const userMessages = messages.filter(msg => msg.author.id === message.author.id);
Promise.all([
member.timeout(604800000, reason),
message.channel.bulkDelete(userMessages).catch(console.error),
message.channel.send({ embeds: [embed] }).then(msg => {
setTimeout(() => {
msg.delete().catch(() => {
return;
})
}, 5000)
})
])
}).catch(console.error);
} else if (attempts == 10 && member.kickable && parseInt(msgCount) === LIMIT) {
bot.db.add(`attempts_${message.guild.id}_${message.author.id}`, 1);
reason = "[AutoMod] Kicked for Spamming!"
let embed = new EmbedBuilder()
.setColor("Red")
.setTitle(`**Moderation Report**`)
.setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL()})
.setFooter({ text: `${bot.user.username} | This message will Auto-Delete in 5 seconds!`, iconURL: bot.user.displayAvatarURL() })
.addFields(
{
name: '**Username:**',
value: `${message.author.username}`,
inline: true
},
{
name: '**Discriminator:**',
value: `${message.author.discriminator}`,
inline: true
},
{
name: '**User Tag:**',
value: `${message.author.tag}`,
inline: true
},
{
name: '**User Mention:**',
value: `${message.author}`,
inline: true
},
{
name: '**UserId:**',
value: `${message.author.id}`,
inline: true
},
{
name: '**Moderation Type:**',
value: 'Kick',
inline: true
},
{
name: '**Reason:**',
value: `${reason}`,
inline: true
},
{
name: '**Moderator:**',
value: `${bot.user.username}`,
inline: true
}
)
.setTimestamp(Date.now());
Promise.all([
member.send({ embeds: [embed] }),
message.channel.send({ embeds: [embed] }).then(msg => {
setTimeout(() => {
msg.delete().catch(() => {
return;
})
}, 5000)
}),
member.kick(reason)
])
// Fetch the spamming user's messages and bulk delete them
message.channel.messages.fetch({ limit: LIMIT }).then(messages => {
const userMessages = messages.filter(msg => msg.author.id === message.author.id);
message.channel.bulkDelete(userMessages).catch(console.error);
}).catch(console.error);
} else if (attempts == 11 && member.bannable && parseInt(msgCount) === LIMIT) {
message.channel.bulkDelete(LIMIT);
bot.db.delete(`attempts_${message.guild.id}_${message.author.id}`)
reason = "[AutoMod] Banned for Spamming!"
let embed = new EmbedBuilder()
.setColor("Red")
.setTitle(`**Moderation Report**`)
.setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL()})
.setFooter({ text: `${bot.user.username} | This message will Auto-Delete in 5 seconds!`, iconURL: bot.user.displayAvatarURL() })
.addFields(
{
name: '**Username:**',
value: `${message.author.username}`,
inline: true
},
{
name: '**Discriminator:**',
value: `${message.author.discriminator}`,
inline: true
},
{
name: '**User Tag:**',
value: `${message.author.tag}`,
inline: true
},
{
name: '**User Mention:**',
value: `${message.author}`,
inline: true
},
{
name: '**UserId:**',
value: `${message.author.id}`,
inline: true
},
{
name: '**Moderation Type:**',
value: 'Ban',
inline: true
},
{
name: '**Reason:**',
value: `${reason}`,
inline: true
},
{
name: '**Moderator:**',
value: `${bot.user.username}`,
inline: true
}
)
.setTimestamp(Date.now());
Promise.all([
message.channel.send({ embeds: [embed] }).then(msg => {
setTimeout(() => {
msg.delete().catch(() => {
return;
})
}, 5000)
}),
member.send({ embeds: [embed] }),
member.ban({ deleteMessageSeconds: 60 * 60, reason: reason })
])
} else {
userData.msgCount = msgCount;
usersMap.set(message.author.id, userData);
}
}
} else {
let fn = setTimeout(() => {
usersMap.delete(message.author.id)
}, 5000);
usersMap.set(message.author.id, {
msgCount: 1,
lastMessage : message,
timer : fn
});
}
} catch(err) {
console.log(err.message);
}
})
// End of Anti-Spam.
// Update Bot's status showing the current number of guilds the bot is in.
bot.on('guildMemberAdd', async (member) => {
// Check if the new member is your bot by comparing user IDs
if (member.user.id === bot.user.id) {
bot.user.setPresence({ activities: [{ name: `${bot.guilds.cache.size} servers!`, type: 3 }], status: 'dnd'})
}
});
bot.on('guildMemberRemove', (member) => {
// Check if the removed member is your bot by comparing user IDs
if (member.user.id === bot.user.id) {
bot.user.setPresence({ activities: [{ name: `${bot.guilds.cache.size} servers!`, type: 3 }], status: 'dnd'})
}
});
// End of Bot Status.
// Suggestions
bot.on('messageCreate', async (message) => {
// If someone sends a message run the code below.
let suggestionchannel = bot.db.get(`LogsSetup_${message.guild.id}.suggestionchannel`)
if (suggestionchannel) {
// If the message was sent in the Suggestion channel continue with the code.
if (message.author.id === bot.user.id) return; // If the sender of the message is the bot stop at this line.
if (message.channel.id === `${suggestionchannel}`) { // If the sender sends the message in the correct channel continue the function.
try {
await message.delete().catch(() => {
return;
})
// Delete the user's message because we are going to convert it into an Embed.
const embed = new EmbedBuilder()
.setTitle(`**New Suggestion!**`)
.setAuthor({ name: message.author.tag, iconURL: message.author.displayAvatarURL() })
.setColor(`Blue`)
.setDescription(`${message.content}`)
.setFooter({ text: message.guild.name })
.setTimestamp(Date.now());
const sendMessage = await message.channel.send({ embeds: [embed] });
if (sendMessage) {
await sendMessage.react(`✅`);
await sendMessage.react(`❌`);
}
} catch (err) {
console.log(err.message);
}
}
}
});
// Embed Buttons
bot.on('interactionCreate', async interaction => {
try {
if (interaction.isButton()) { // If the interaction contains a button continue.
// Handle different button IDs
if (interaction.customId === 'claim') { // If the button ID is claim continue.
if (interaction.member.permissions.has('ModerateMembers' || 'BanMembers' || 'KickMembers' || 'Administrator')) { // If the member clicking the button has any of these permissions continue.
// Code to run when 'myButtonId' is clicked
if (interaction.message) {
await interaction.message.edit({ components: [ new ActionRowBuilder().addComponents( new ButtonBuilder().setCustomId('close').setLabel('Close').setEmoji('🔒').setStyle(ButtonStyle.Danger)).addComponents( new ButtonBuilder().setCustomId('closewithreason').setLabel('Close with Reason').setEmoji('🗒️').setStyle(ButtonStyle.Danger)) ] });
}
if (interaction) {
await interaction.reply({ content: `Your ticket has been claimed by ${interaction.member.user}`, ephemeral: true })
}
} else { // Member clicking the button doesn't have permission therefore show them an error message.
if (interaction) {
await interaction.reply({ content: `You don't have permission to claim this ticket.`, ephemeral: true })
}
}
}
if (interaction.customId === 'close') { // Close ticket button was clicked so we are going to delete the ticket channel that was created.
// Code to run when 'myButtonId' is clicked
await interaction.channel.delete().catch(() => {
return;
})
}
if (interaction.customId === 'closewithreason') { // Close ticket with reason was clicked so open up a form modal to insert the reason.
// Handle the button click and open the form
const modal = new ModalBuilder()
.setCustomId('closewithreasonmodal')
.setTitle('Close')
.addComponents([
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('closereasoninput')
.setLabel('Reason:')
.setStyle(TextInputStyle.Paragraph)
.setRequired(true),
),
]);
if (interaction) {
await interaction.showModal(modal);
}
}
if (interaction.customId === 'serversetup') { // Server setup button was clicked so open up a modal to fill in the setting configs for the server.
// Handle the button click and open the form
const modal = new ModalBuilder()
.setCustomId('serversetupmodal')
.setTitle('Server Setup')
.addComponents([
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('setcookieinput')
.setLabel('Roblox Cookie:')
.setStyle(TextInputStyle.Paragraph)
.setRequired(true),
),
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('setgroupinput')
.setLabel('Roblox Group ID:')
.setStyle(TextInputStyle.Short)
.setRequired(true)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('setminrankinput')
.setLabel('Minimum Rank:')
.setStyle(TextInputStyle.Short)
.setRequired(true)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('setgameidinput')
.setLabel('Verification Game ID:')
.setStyle(TextInputStyle.Short)
.setRequired(false)
),
]);
if (interaction) {
await interaction.showModal(modal);
}
}
if (interaction.customId === 'setuplogs') { // Setup logs button was clicked so open a modal to fill in the log channel settings.
// Handle the button click and open the form
const modal = new ModalBuilder()
.setCustomId('setuplogsmodal')
.setTitle('Logs Setup')
.addComponents([
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('setshoutchannel')
.setLabel('Roblox Group Shout Channel ID:')
.setStyle(TextInputStyle.Short)
.setRequired(true),
),
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('setserverlogchannel')
.setLabel('Discord Logs Channel ID:')
.setStyle(TextInputStyle.Short)
.setRequired(true)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('setsuggestionchannel')
.setLabel('Suggestions Channel ID:')
.setStyle(TextInputStyle.Short)
.setRequired(true)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('setticketchannel')
.setLabel('Ticket Channel ID:')
.setStyle(TextInputStyle.Short)
.setRequired(true)
),
]);
if (interaction) {
await interaction.showModal(modal);
}
}
}
// End of Buttons
// Beginning of Modal Submissions
if (interaction.type === InteractionType.ModalSubmit) { // If a form modal was submitted do something.
if (interaction.customId === 'closewithreasonmodal') { // Reason for closing ticket was submitted so DM the user the reason and close the ticket channel that was created.
const response =
interaction.fields.getTextInputValue('closereasoninput');
await interaction.deferReply();
const embed = new EmbedBuilder()
.setTitle(`Ticket Closed!`)
.setDescription(`Your ticket has been closed!\n**Reason:** ${response}\nIf you are still having issues please open another ticket by running **/ticket** command in ${interaction.guild.name} bot commands channel!`)
.setColor('Red')
.setAuthor({ name: interaction.member.user.tag, iconURL: interaction.member.user.displayAvatarURL() })
.setTimestamp(Date.now())
.setFooter({ text: interaction.guild.name })
await interaction.member.send({ embeds: [embed] })
await interaction.channel.delete().catch((err) => {
console.log(err.message)
})
}
if (interaction.customId === 'serversetupmodal') { // Server settings were submitted so save the settings to that specific server. Useful for handling multi-guilds.
await interaction.deferReply({ ephemeral: true })
const response = interaction.fields.getTextInputValue('setcookieinput');
const response2 = interaction.fields.getTextInputValue('setgroupinput');
const response3 = interaction.fields.getTextInputValue('setminrankinput');
const response4 = interaction.fields.getTextInputValue('setgameidinput');
await interaction.editReply(`✅ **SUCCESS** | This server has been set up successfully!\nThis message will auto-delete in 5 seconds!`).then(() => {
setTimeout(() => {
interaction.deleteReply().catch((err) => {
return;
})
}, 5000)
})
bot.db.set(`ServerSetup_${interaction.guild.id}`, { rblxcookie: response, groupid: response2, minrank: response3, gameid: response4})
const RobloxCookie = bot.db.get(`ServerSetup_${interaction.guild.id}.rblxcookie`)
if (RobloxCookie) {
await rbxbot.setCookie(RobloxCookie, interaction.guild.id);
const CurrentUser = await rbxbot.getCurrentUser("UserName");
interaction.guild.members.me.setNickname(CurrentUser);
}
}
if (interaction.customId === 'setuplogsmodal') { // Log settings were submitted so save the settings to that specific server. Useful for handling multi-guilds.
await interaction.deferReply({ ephemeral: true })
const response = interaction.fields.getTextInputValue('setshoutchannel');
const response2 = interaction.fields.getTextInputValue('setserverlogchannel');
const response3 = interaction.fields.getTextInputValue('setsuggestionchannel');
const response4 = interaction.fields.getTextInputValue('setticketchannel');
await interaction.editReply(`✅ **SUCCESS** | Logs have been successfully configured!\nThis message will auto-delete in 5 seconds!`).then(() => {
setTimeout(() => {
interaction.delete().catch((err) => {
return;
})
}, 5000)
})
bot.db.set(`LogsSetup_${interaction.guild.id}`, { shoutchannel: response, serverlogs: response2, suggestionchannel: response3, ticketchannel: response4 })
}
}
} catch(err) {
console.log(err.message)
}
});
// End of Modal Submissions.
// Suggestions Upvote and Downvote system.