-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
758 lines (646 loc) · 24.7 KB
/
Copy pathindex.js
File metadata and controls
758 lines (646 loc) · 24.7 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
const { Client, Intents, Collection, MessageActionRow, MessageButton, MessageSelectMenu , Modal, TextInputComponent, MessageEmbed} = require('discord.js');
const fs = require('fs');
global.config = require('./config');
const path = require('path');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
]
});
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
const pointsFile = path.join(__dirname, "points.json");
function loadPoints() {
if (!fs.existsSync(pointsFile)) return {};
return JSON.parse(fs.readFileSync(pointsFile, "utf8"));
}
function savePoints(data) {
fs.writeFileSync(pointsFile, JSON.stringify(data, null, 2));
}
function setPoints(userId, points) {
const data = loadPoints();
if (!data[userId] || typeof data[userId] !== "object") {
data[userId] = { points: 0, wins: 0, losses: 0, dailyChange: 0 };
}
data[userId].points = points;
savePoints(data);
return points;
}
function addPoints(userId, amount) {
const data = loadPoints();
if (!data[userId] || typeof data[userId] !== "object") {
data[userId] = { points: 0, wins: 0, losses: 0, dailyChange: 0 };
}
const userData = data[userId];
const newPoints = Math.max(0, userData.points + amount);
userData.points = newPoints;
userData.dailyChange += amount;
savePoints(data);
return newPoints;
}
client.once('ready', async () => {
config.guildIds.forEach(guildID => {
const guild = client.guilds.cache.get(guildID);
if (guild) {
console.log(`[Sync Studios]: Commands Loaded In ${guild.name}`);
client.user.setActivity('League', {
type: 'WATCHING' // Options: PLAYING, STREAMING, LISTENING, WATCHING, COMPETING
});
console.log("[Sync Studios] League Bot: Loading ....")
console.log("[Sync Studios] Support: https://disboard.org/server/join/1119734000974565439")
console.log("[Sync Studios] Made By ScratchStack")
guild.commands.set(Array.from(client.commands.values()).map(cmd => cmd.data)).catch(err => {
console.error(`[Sync Studios]: Failed to set commands for ${guild.name}:`, err);
});
} else {
console.log(`[Sync Studios]: Guild not found: ${guildID}`);
}
});
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction, client);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'An error occurred while executing this command!', ephemeral: true });
}
});
const configPath = path.resolve(__dirname, './config.json');
client.on('guildMemberAdd', async member => {
if (!fs.existsSync(configPath)) return;
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
const guildConfig = config[member.guild.id];
if (!guildConfig) return;
const channel = member.guild.channels.cache.get(guildConfig.channel);
if (!channel) return;
let message = guildConfig.message
.replace(/\${member\.id}/g, member.id)
.replace(/\${member\.tag}/g, member.user.tag)
.replace(/\${member\.username}/g, member.user.username)
.replace(/\${member\.discriminator}/g, member.user.discriminator)
.replace(/\${member\.createdAt}/g, member.user.createdAt.toLocaleDateString())
.replace(/\${member}/g, `<@${member.id}>`)
.replace(/\${guild\.name}/g, member.guild.name)
.replace(/\${guild\.memberCount}/g, member.guild.memberCount.toString());
if (message.startsWith('--embed')) {
message = message.replace('--embed', '').trim();
const embed = new MessageEmbed()
.setColor('#2F3136')
.setDescription(message)
.setFooter({ text: `Welcome to ${member.guild.name}` })
.setTimestamp()
.setAuthor({ name: member.user.tag, iconURL: member.user.displayAvatarURL() });
channel.send({ embeds: [embed] });
} else {
channel.send({ content: message });
}
});
client.once('ready', async () => {
const queueChannelId = "1407411824306950367";
const channel = client.channels.cache.get(queueChannelId);
if (!channel) return console.error("Queue channel not found!");
const embed = new MessageEmbed()
.setTitle('🏆 1v1 League Queue')
.setDescription('Prove yourself as the best player on the platform.\nMatchmake anonymously against another player to see who will reign victorious!')
.setColor('#ff0000')
.setImage('');
const row = new MessageActionRow().addComponents(
new MessageSelectMenu()
.setCustomId('queue_select')
.setPlaceholder('🎮 Select Matchmaking Gamemode')
.addOptions([
{
label: '1v1 Vanwars Combat Pistols',
value: 'vanwars_combat',
description: 'Compete at Vanwars using Combat Pistols'
},
{
label: '1v1 Vanwars AP Pistols',
value: 'vanwars_ap',
description: 'Compete at Vanwars using AP Pistols'
},
{
label: '1v1 Ramps Combat Pistols',
value: 'ramps_combat',
description: 'Compete at Ramps using Combat Pistols'
}
])
);
if (channel) {
const messages = await channel.messages.fetch({ limit: 10 });
const alreadySent = messages.find(msg => msg.author.id === client.user.id);
if (!alreadySent) {
await channel.send({ embeds: [embed], components: [row] });
console.log("[Z]: Queue embed sent.");
} else {
console.log("[Z]: Queue embed already exists, skipping send.");
}
}
});
client.on('interactionCreate', async (interaction) => {
if (interaction.isSelectMenu() && interaction.customId === 'queue_select') {
const choice = interaction.values[0];
if (!client.queue) client.queue = new Map();
client.queue.set(interaction.user.id, {
gamemode: choice,
timestamp: Date.now()
});
const embed = new MessageEmbed()
.setColor('#5865F2')
.setTitle('Joined Matchmaking Queue')
.setDescription(
`**Gamemode:** \`${choice}\`\n\n` +
`Your team has entered the matchmaking queue and will find an opponent soon.\n` +
`You will receive a ✉️ Direct Message once your match begins.`
)
.setFooter({ text: 'Use the button below to leave the queue.' })
.setTimestamp();
const row = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId('leave_queue')
.setLabel('Leave Queue')
.setStyle('DANGER')
);
await interaction.reply({
embeds: [embed],
components: [row],
ephemeral: true
});
}
if (interaction.isButton() && interaction.customId === 'leave_queue') {
if (!client.queue || !client.queue.has(interaction.user.id)) {
return interaction.reply({
content: '⚠️ You are not currently in any queue.',
ephemeral: true
});
}
client.queue.delete(interaction.user.id);
const embed = new MessageEmbed()
.setColor('#ED4245')
.setTitle('❌ Left Matchmaking Queue')
.setDescription('You have been removed from the matchmaking queue.')
.setTimestamp();
await interaction.update({
embeds: [embed],
components: []
});
}
});
client.once('ready', async () => {
const channel = await client.channels.fetch('1407411827620446279'); // 2v2 channel ID
if (!channel) return console.error('❌ Channel not found!');
const messages = await channel.messages.fetch({ limit: 10 });
const alreadySent = messages.some(msg =>
msg.author.id === client.user.id &&
msg.embeds.length > 0 &&
msg.embeds[0].title === '⚔️ 2v2 League Queue'
);
if (alreadySent) {
console.log('⚔️ 2v2 Queue embed already exists, not sending again.');
return;
}
const embed = new MessageEmbed()
.setColor('#2ECC71')
.setTitle('⚔️ 2v2 League Queue')
.setDescription(
`Form your team and prove your strength!\n` +
`Queue up for **2v2 matches** and get paired with opponents.\n\n` +
`Select a gamemode below to enter the matchmaking queue.`
)
.setFooter({ text: 'You will receive a DM when your match begins.' });
const row = new MessageActionRow().addComponents(
new MessageSelectMenu()
.setCustomId('queue_select_2v2')
.setPlaceholder('🎮 Select 2v2 Matchmaking Gamemode')
.addOptions([
{
label: '2v2 Ramps Combat Pistols',
description: 'Compete at Ramps using Combat Pistols',
value: '2v2_ramps_combat'
},
{
label: '2v2 Ramps AP Pistols',
description: 'Compete at Ramps using AP Pistols',
value: '2v2_ramps_ap'
}
])
);
client.on('interactionCreate', async (interaction) => {
if (interaction.isSelectMenu() && interaction.customId === 'queue_select_3v3') {
const choice = interaction.values[0];
if (!client.teams) client.teams = new Map();
client.teams.set(interaction.user.id, {
gamemode: choice,
members: [interaction.user.id]
});
const embed = new MessageEmbed()
.setTitle('👥 Teammate Selection')
.setDescription(`You have selected **1/3 players** required for this gamemode.\n\nYour Team:\n<@${interaction.user.id}>`)
.setColor('#e74c3c');
const row = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId('add_teammate')
.setLabel('Add Player')
.setStyle('PRIMARY')
.setEmoji('👤'),
new MessageButton()
.setCustomId('remove_teammate')
.setLabel('Remove Player')
.setStyle('DANGER')
.setEmoji('💥')
);
await interaction.reply({ embeds: [embed], components: [row], ephemeral: true });
}
if (interaction.isButton() && interaction.customId === 'add_teammate') {
const modal = new Modal()
.setCustomId('add_teammate_modal')
.setTitle('Add a Teammate');
const input = new TextInputComponent()
.setCustomId('teammate_id')
.setLabel('Enter Discord User ID')
.setStyle('SHORT')
.setPlaceholder('Example: 123456789012345678')
.setRequired(true);
const row = new MessageActionRow().addComponents(input);
modal.addComponents(row);
await interaction.showModal(modal);
}
if (interaction.isModalSubmit() && interaction.customId === 'add_teammate_modal') {
const teammateId = interaction.fields.getTextInputValue('teammate_id');
const team = client.teams.get(interaction.user.id);
if (!team) {
return interaction.reply({ content: '⚠️ No active team found.', ephemeral: true });
}
const user = await client.users.fetch(teammateId).catch(() => null);
if (!user) {
return interaction.reply({ content: '❌ Invalid user ID.', ephemeral: true });
}
if (team.members.includes(teammateId)) {
return interaction.reply({ content: '⚠️ That player is already in your team.', ephemeral: true });
}
if (team.members.length >= 3) {
return interaction.reply({ content: '⚠️ Your team is already full.', ephemeral: true });
}
team.members.push(teammateId);
const embed = new MessageEmbed()
.setTitle('👥 Teammate Selection')
.setDescription(`You have selected **${team.members.length}/3 players** required for this gamemode.\n\nYour Team:\n${team.members.map(id => `<@${id}>`).join('\n')}`)
.setColor('#2ecc71');
if (team.members.length === 3) {
client.queue = client.queue || [];
client.queue.push(team);
return interaction.reply({
content: `✅ Team completed!\n:loading: **Joined Matchmaking Queue**\nGamemode: \`${team.gamemode}\`\n\nYour team will find an opponent soon. You’ll receive a ✉️ Direct Message once your match begins.`,
ephemeral: true
});
}
return interaction.reply({ embeds: [embed], ephemeral: true });
}
});
await channel.send({ embeds: [embed], components: [row] });
console.log('✅ 2v2 Queue embed sent.');
});
client.once('ready', async () => {
const channel = await client.channels.fetch('1407411831273951336'); // 3v3 channel ID
if (!channel) return console.error('❌ Channel not found!');
const messages = await channel.messages.fetch({ limit: 10 });
const alreadySent = messages.some(msg =>
msg.author.id === client.user.id &&
msg.embeds.length > 0 &&
msg.embeds[0].title === '⚔️ 3v3 League Queue'
);
if (alreadySent) {
console.log('⚔️ 3v3 Queue embed already exists, not sending again.');
return;
}
const embed = new MessageEmbed()
.setColor('#3498DB')
.setTitle('⚔️ 3v3 League Queue')
.setDescription(
`Gather your squad of 3 and show your skills!\n` +
`Queue up for **3v3 matches** and get paired with opponents.\n\n` +
`Select a gamemode below to enter the matchmaking queue.`
)
.setFooter({ text: 'You will receive a DM when your match begins.' });
const row = new MessageActionRow().addComponents(
new MessageSelectMenu()
.setCustomId('queue_select_3v3')
.setPlaceholder('🎮 Select 3v3 Matchmaking Gamemode')
.addOptions([
{
label: '3v3 Stables Combat Pistols',
description: 'Fight at Stables with Combat Pistols',
value: '3v3_stables_combat'
},
{
label: '3v3 Stables AP Pistols',
description: 'Fight at Stables with AP Pistols',
value: '3v3_stables_ap'
},
{
label: '3v3 Soccer Arena Combat Pistols',
description: 'Play at Soccer Arena with Combat Pistols',
value: '3v3_soccer_combat'
},
{
label: '3v3 Soccer Arena AP Pistols',
description: 'Play at Soccer Arena with AP Pistols',
value: '3v3_soccer_ap'
}
])
);
await channel.send({ embeds: [embed], components: [row] });
console.log('✅ 3v3 Queue embed sent.');
});
client.queue3v3 = new Map();
client.matchQueue3v3 = [];
/*
const fakeTeam = {
leader: "123456789012345678", // fake discord ID
gamemode: "3v3_stables_combat",
team: [
"155149108183695360", // leader
"155149108183695360", // teammate 1
"1407451194523123853", // teammate 2
],
timestamp: Date.now(),
};
client.matchQueue3v3.push(fakeTeam);
console.log("[3v3] Fake team added:", fakeTeam.team);
*/
client.on("interactionCreate", async (interaction) => {
if (interaction.isSelectMenu() && interaction.customId === "queue_select_3v3") {
const choice = interaction.values[0];
if (!client.queue3v3.has(interaction.user.id)) {
client.queue3v3.set(interaction.user.id, {
leader: interaction.user.id,
gamemode: choice,
team: [interaction.user.id],
timestamp: Date.now(),
});
}
const team = client.queue3v3.get(interaction.user.id);
const embed = new MessageEmbed()
.setColor("#e67e22")
.setTitle("👥 3v3 Team Setup")
.setDescription(
`Gamemode: \`${choice}\`\n\n` +
`You are the **team leader**.\n` +
`Add 2 teammates by entering their Discord IDs.\n\n` +
`**Current Team:**\n${team.team.map((id) => `<@${id}>`).join("\n")}`
)
.setFooter({
text: "When 3 players are added, the queue will begin automatically.",
});
const row = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId("team_add")
.setLabel("➕ Add Player")
.setStyle("PRIMARY"),
new MessageButton()
.setCustomId("team_remove")
.setLabel("➖ Remove Player")
.setStyle("SECONDARY"),
new MessageButton()
.setCustomId("team_leave")
.setLabel("🚪 Leave Queue")
.setStyle("DANGER")
);
return interaction.reply({ embeds: [embed], components: [row], ephemeral: true });
}
if (interaction.isButton() && interaction.customId === "team_add") {
const modal = new Modal()
.setCustomId("add_player_modal")
.setTitle("Add Teammate")
.addComponents(
new MessageActionRow().addComponents(
new TextInputComponent()
.setCustomId("player_id")
.setLabel("Enter Teammate Discord ID")
.setStyle("SHORT")
.setRequired(true)
)
);
return interaction.showModal(modal);
}
if (interaction.isModalSubmit() && interaction.customId === "add_player_modal") {
const teammateId = interaction.fields.getTextInputValue("player_id");
const team = client.queue3v3.get(interaction.user.id);
if (!team) {
return interaction.reply({
content: "❌ You are not leading a team.",
ephemeral: true,
});
}
if (team.team.includes(teammateId)) {
return interaction.reply({
content: "⚠️ That player is already on your team.",
ephemeral: true,
});
}
if (team.team.length >= 3) {
return interaction.reply({
content: "⚠️ Your team already has 3 players.",
ephemeral: true,
});
}
team.team.push(teammateId);
client.queue3v3.set(interaction.user.id, team);
const embed = new MessageEmbed()
.setColor("#e67e22")
.setTitle("👥 3v3 Team Setup")
.setDescription(
`Gamemode: \`${team.gamemode}\`\n\n` +
`**Current Team:**\n${team.team.map((id) => `<@${id}>`).join("\n")}`
);
await interaction.reply({
content: `✅ Added <@${teammateId}> to your team.`,
embeds: [embed],
ephemeral: true,
});
if (team.team.length === 3) {
client.matchQueue3v3.push(team);
console.log(`[3v3] Team full: ${team.team.join(", ")}`);
if (client.matchQueue3v3.length >= 2) {
const [team1, team2] = client.matchQueue3v3.splice(0, 2);
const guild = interaction.guild;
const channel = await guild.channels.create(`3v3-match-${Date.now()}`, {
type: "GUILD_TEXT",
permissionOverwrites: [
{ id: guild.id, deny: ["VIEW_CHANNEL"] },
...team1.team
.filter(id => guild.members.cache.has(id))
.map(id => ({
id,
allow: ["VIEW_CHANNEL", "SEND_MESSAGES"],
})),
...team2.team
.filter(id => guild.members.cache.has(id))
.map(id => ({
id,
allow: ["VIEW_CHANNEL", "SEND_MESSAGES"],
})),
],
});
const matchEmbed = new MessageEmbed()
.setColor("#e74c3c")
.setTitle("📋 Match Controls")
.setDescription(
`Team leaders can use the panel below to control the match.\n` +
`Make sure to comply with our rules!\n\n` +
`**Team 1:**\n${team1.team.map((id) => `<@${id}>`).join("\n")}\n\n` +
`**Team 2:**\n${team2.team.map((id) => `<@${id}>`).join("\n")}`
);
const controlsRow = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId("request_staff")
.setLabel("🔔 Request Staff")
.setStyle("PRIMARY"),
new MessageButton()
.setCustomId("assign_winner")
.setLabel("⚡ Assign Winner")
.setStyle("DANGER")
);
await channel.send({ embeds: [matchEmbed], components: [controlsRow] });
console.log(`[3v3] Match started in #${channel.name}`);
}
}
}
});
const ranks = [
{ name: "Noob", min: 0, max: 399, roleId: "1407411676734689401" },
{ name: "Rookie", min: 400, max: 1499, roleId: "1407411675363147926" },
{ name: "Pro", min: 1500, max: 1799, roleId: "1407411674201198673" },
{ name: "Legend", min: 1800, max: 2499, roleId: "1407411671122706594" },
{ name: "God", min: 2500, max: 3999, roleId: "1407411669793116331" },
{ name: "Demon", min: 4000, max: 4999, roleId: "1409568754773393548" },
{ name: "Undisputed", min: 5000, max: Infinity, roleId: "1409568951200911372" }
];
async function updateRankRoles(member, points) {
const guild = member.guild;
const newRank = ranks.find(r => points >= r.min && points <= r.max);
if (!newRank) return;
const roleIds = ranks.map(r => r.roleId);
await member.roles.remove(roleIds).catch(() => null);
const role = guild.roles.cache.get(newRank.roleId);
if (role) await member.roles.add(role).catch(() => null);
return newRank;
}
client.on("interactionCreate", async (interaction) => {
if (interaction.isButton() && interaction.customId === "assign_winner") {
const row = new MessageActionRow().addComponents(
new MessageSelectMenu()
.setCustomId("select_winner_team")
.setPlaceholder("Select winning team")
.addOptions([
{ label: "Team 1", value: "1" },
{ label: "Team 2", value: "2" }
])
);
return interaction.reply({
content: "Choose the winning team:",
components: [row],
ephemeral: true
});
}
if (interaction.isSelectMenu() && interaction.customId === "select_winner_team") {
const matchChannel = interaction.channel;
const messages = await matchChannel.messages.fetch({ limit: 10 });
const matchMsg = messages.find(
(m) => m.embeds.length && m.embeds[0].title === "📋 Match Controls"
);
if (!matchMsg) {
return interaction.reply({
content: "⚠️ Could not find match data.",
ephemeral: true
});
}
const embed = matchMsg.embeds[0];
const lines = embed.description.split("\n");
const team1Start = lines.indexOf("**Team 1:**");
const team2Start = lines.indexOf("**Team 2:**");
const team1Ids = lines
.slice(team1Start + 1, team2Start)
.flatMap(line => [...line.matchAll(/<@!?(\d+)>/g)].map(m => m[1]));
const team2Ids = lines
.slice(team2Start + 1)
.flatMap(line => [...line.matchAll(/<@!?(\d+)>/g)].map(m => m[1]));
const winnerTeam = interaction.values[0] === "1" ? team1Ids : team2Ids;
const loserTeam = interaction.values[0] === "1" ? team2Ids : team1Ids;
const guild = interaction.guild;
const resultEmbed = new MessageEmbed()
.setColor("#2ecc71")
.setTitle("🏆 Match Result");
let winnerText = "";
for (const id of winnerTeam) {
const member = guild.members.cache.get(id);
if (!member) continue;
const newPts = addPoints(id, 15);
const rank = await updateRankRoles(member, newPts);
winnerText += `${member} (+15 pts)\n`;
}
let loserText = "";
for (const id of loserTeam) {
const member = guild.members.cache.get(id);
if (!member) continue;
const newPts = addPoints(id, -10);
const rank = await updateRankRoles(member, newPts);
loserText += `${member} (-10 pts)\n`;
}
resultEmbed.setDescription(`**Winner:**\n${winnerText}\n**Loser:**\n${loserText}`);
const resultsChannel = guild.channels.cache.get(config.winloss_announce_channel_id);
if (resultsChannel && resultsChannel.isText()) {
await resultsChannel.send({ embeds: [resultEmbed] });
}
await interaction.reply({
content: "✅ Match result recorded! This channel will now be deleted.",
ephemeral: true
});
setTimeout(async () => {
try {
await matchChannel.delete();
} catch (err) {
}
}, 5000);
}
});
function getUserData(userId) {
const data = loadPoints();
if (!data[userId] || typeof data[userId] !== "object") {
data[userId] = { points: 0, wins: 0, losses: 0, dailyChange: 0 };
savePoints(data);
}
return data[userId];
}
client.on("interactionCreate", async (interaction) => {
if (!interaction.isModalSubmit()) return;
if (interaction.customId === "nicknameModal") {
const nickname = interaction.fields.getTextInputValue("nicknameInput");
const data = getUserData(interaction.user.id);
const points = data.points || 0;
const finalName = `[${points}] ${nickname}`;
try {
await interaction.member.setNickname(finalName);
await interaction.reply({
content: `✅ Your nickname has been set to **${finalName}**`,
ephemeral: true
});
} catch (err) {
console.error("Nickname error:", err);
await interaction.reply({
content: "❌ I couldn’t change your nickname. Do I have permission?",
ephemeral: true
});
}
}
});
client.login(config.token);