-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
504 lines (407 loc) · 28.7 KB
/
index.js
File metadata and controls
504 lines (407 loc) · 28.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
require('dotenv').config();
const {
Client, GatewayIntentBits, REST, Routes, SlashCommandBuilder, ChannelType,
ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder,
ModalBuilder, TextInputBuilder, TextInputStyle, MessageFlags, Events
} = require('discord.js');
const express = require('express');
const app = express();
app.get('/', (req, res) => res.send('Bot is Online! 🟢'));
// สั่งให้ดึงพอร์ตจาก Render อัตโนมัติ ถ้าไม่มีให้ใช้ 3000
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`✅ ระบบ Web Server ทำงานแล้วที่พอร์ต ${port}!`));
const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus } = require('@discordjs/voice');
const googleTTS = require('google-tts-api');
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
// ✨ นำเข้าเครื่องมือ Google Sheets
const { GoogleSpreadsheet } = require('google-spreadsheet');
const { JWT } = require('google-auth-library');
// 🚨 ================= ตั้งค่า ID ต่างๆ ================= 🚨
const LOG_CHANNEL_ID = '1473054497130676274';
const ANNOUNCE_CHANNEL_ID = '1473059682590523453';
const ROLE_PENDING_ID = '1473059083203379231';
const ROLE_APPROVED_ID = '1430676111125250118';
const ROLE_TO_PING_ID = '1430676111125250118';
const LISTNAME_CHANNEL_ID = '1432818365814280233';
// 🚨 ✨ [เพิ่มใหม่] ใส่ ID ห้อง Logs สำหรับบันทึกการใช้คำสั่งของแอดมิน
const COMMAND_LOG_CHANNEL_ID = '1474684056972165298';
// 🚨 ✨ ใส่ ID Google Sheet ของคุณ
const SHEET_ID = '1yuHgVtmeWNhMgtakDf_pvvWR-6jtkmHFsQGi8y8cZtI';
const ADMIN_ROLES_ID = [
'1412006993534648370',
'1470880861875601459'
];
const ADMIN_COMMANDS = ['setup', 'shake', 'addlist', 'removelist', 'editlist'];
const EMOJI_JOIN_BTN = { name: 'lolipop_kjy', id: '1473056898575110236', animated: true };
const EMOJI_APPROVE_BTN = { name: 'rainbowheart', id: '1473063851296821278', animated: true };
const EMOJI_REJECT_BTN = { name: 'btdb1crying', id: '1473063886012944414', animated: true };
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMembers
]
});
// ✨ [เพิ่มใหม่] ฟังก์ชันสำหรับส่ง Log เข้าห้อง
async function sendActionLog(user, actionDetail) {
if (!COMMAND_LOG_CHANNEL_ID || COMMAND_LOG_CHANNEL_ID === 'ใส่_ID_ห้อง_LOG_ใหม่_ตรงนี้') return;
try {
const logChannel = await client.channels.fetch(COMMAND_LOG_CHANNEL_ID).catch(() => null);
if (!logChannel) return;
const logEmbed = new EmbedBuilder()
.setTitle('⛔ ประวัติการใช้คำสั่ง')
.setColor('#e5ff00')
.setAuthor({ name: user.tag, iconURL: user.displayAvatarURL({ dynamic: true }) })
.setDescription(`**User :** <@${user.id}>\n**Command :** ${actionDetail}`)
.setTimestamp();
await logChannel.send({ embeds: [logEmbed] });
} catch (error) {
console.error('❌ [Log] เกิดข้อผิดพลาดในการส่ง Log:', error.message);
}
}
// ✨ โหลดไฟล์กุญแจ API Google
let creds;
try {
creds = require('./google-key.json');
} catch (e) {
console.log('⚠️ ไม่พบไฟล์ google-key.json ระบบอัปเดตชีตจะไม่ทำงาน');
}
// ✨ ฟังก์ชันอัปเดตชีตแบบฉลาด
async function syncGoogleSheet(currentList) {
if (!creds || !SHEET_ID) return;
try {
console.log('⏳ [Sheet] กำลังเชื่อมต่อเข้า Google Sheet...');
const serviceAccountAuth = new JWT({
email: creds.client_email,
key: creds.private_key,
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
});
const doc = new GoogleSpreadsheet(SHEET_ID, serviceAccountAuth);
await doc.loadInfo();
const sheet = doc.sheetsByIndex[0];
let existingData = {};
try {
await sheet.loadHeaderRow();
const rows = await sheet.getRows();
for (const row of rows) {
const rowData = row.toObject();
if (rowData.name) {
existingData[rowData.name] = rowData;
}
}
} catch (e) {
await sheet.setHeaderRow(['name', 'role', 'fbLink', 'image']);
}
console.log('⏳ [Sheet] กำลังจัดเรียงข้อมูลรายชื่อใหม่...');
await sheet.clearRows();
const rowsToAdd = currentList.map((nameStr) => {
let icNameOnly = nameStr;
if (nameStr.includes('(')) {
icNameOnly = nameStr.split('(')[0].trim();
}
const oldData = existingData[icNameOnly] || {};
return {
'name': icNameOnly,
'role': oldData.role || 'MEMBER',
'fbLink': oldData.fbLink || '',
'image': oldData.image || ''
};
});
if (rowsToAdd.length > 0) {
await sheet.addRows(rowsToAdd);
}
console.log('✅ [Sheet] อัปเดตลง Google Sheet สำเร็จแล้ว!');
} catch (error) {
console.error('❌ [Sheet] เกิดข้อผิดพลาด:', error.message);
}
}
// ✨ ฟังก์ชันจัดการ Listname อัตโนมัติในดิสคอร์ด
async function updateKJYList(client, guild, action, data, position = null) {
try {
console.log(`\n⏳ [Listname] ประมวลผล: ${action} -> ${data} (ตำแหน่ง: ${position || 'ท้ายสุด'})`);
const listChannel = await client.channels.fetch(LISTNAME_CHANNEL_ID).catch(() => null);
if (!listChannel) return console.log('❌ [Listname] หาระบบห้อง Listname ไม่เจอ');
const messages = await listChannel.messages.fetch({ limit: 10 }).catch(() => null);
let lastListMsg = null;
if (messages) {
lastListMsg = messages.find(m =>
m.author.id === client.user.id &&
m.embeds.length > 0 &&
m.embeds[0].title &&
m.embeds[0].title.includes('KJY Listname')
);
}
let currentList = [];
if (lastListMsg && lastListMsg.embeds[0].description) {
currentList = lastListMsg.embeds[0].description.split('\n')
.map(line => line.replace(/^\*\*\d+\.\*\*\s*/, '').trim())
.filter(line => line.length > 0 && !line.includes('ยังไม่มีรายชื่อ'));
}
if (action === 'add') {
if (position && position > 0 && position <= currentList.length + 1) {
currentList.splice(position - 1, 0, data);
} else {
currentList.push(data);
}
} else if (action === 'remove') {
const index = data - 1;
if (index >= 0 && index < currentList.length) {
currentList.splice(index, 1);
}
} else if (action === 'edit') {
const index = position - 1;
if (index >= 0 && index < currentList.length) {
currentList[index] = data;
}
}
if (lastListMsg) {
await lastListMsg.delete().catch(err => console.log(`⚠️ [Listname] ลบเก่าไม่ได้: ${err.message}`));
}
const newDesc = currentList.length > 0
? currentList.map((name, index) => `**${index + 1}.** ${name}`).join('\n')
: '*ยังไม่มีรายชื่อในขณะนี้*';
const listEmbed = new EmbedBuilder()
.setTitle('🔮 KJY Listname Member')
.setDescription(newDesc)
.setColor('#b800be')
.setImage('https://media.discordapp.net/attachments/1412006598934528020/1434915858181787808/kjylistname.png?ex=69947e88&is=69932d08&hm=e80b0d0176f392655c2c6f8e089692c52c0681d21ded502d178e8a49088ecb92&=&format=webp&quality=lossless&width=1554&height=874')
.setFooter({ text: `Last Update!!` })
.setTimestamp();
if (guild) {
const serverIcon = guild.iconURL({ dynamic: true });
if (serverIcon) {
listEmbed.setThumbnail(serverIcon);
}
}
await listChannel.send({ embeds: [listEmbed] });
console.log('✅ [Listname] อัปเดตรายชื่อใน Discord สำเร็จ!');
await syncGoogleSheet(currentList);
} catch (error) {
console.error('❌ [Listname] เกิดข้อผิดพลาด:', error);
}
}
const commands = [
new SlashCommandBuilder().setName('ping').setDescription('เช็คสถานะการตอบสนองของบอท'),
new SlashCommandBuilder().setName('setup').setDescription('สร้างแผงควบคุมระบบรับสมัคร Whitelist'),
new SlashCommandBuilder().setName('say').setDescription('สั่งให้บอทเข้ามาพูดในห้องเสียง')
.addStringOption(opt => opt.setName('message').setDescription('พิมพ์ข้อความ').setRequired(true)),
new SlashCommandBuilder().setName('shake').setDescription('เขย่าเรียกเพื่อนให้ตื่น (ย้ายห้องสลับไปมารัวๆ)')
.addUserOption(opt => opt.setName('target').setDescription('เลือกคนที่ต้องการเขย่า!').setRequired(true)),
new SlashCommandBuilder().setName('addlist').setDescription('เพิ่มรายชื่อเข้า List แบบแมนนวล')
.addStringOption(opt => opt.setName('name').setDescription('ชื่อที่ต้องการเพิ่ม').setRequired(true))
.addIntegerOption(opt => opt.setName('position').setDescription('ลำดับที่ต้องการแทรก (ปล่อยว่างเพื่อต่อท้าย)')),
new SlashCommandBuilder().setName('editlist').setDescription('แก้ไขชื่อใน List เดิม')
.addIntegerOption(opt => opt.setName('number').setDescription('เลขลำดับที่ต้องการแก้').setRequired(true))
.addStringOption(opt => opt.setName('new_name').setDescription('ชื่อใหม่ที่ถูกต้อง').setRequired(true)),
new SlashCommandBuilder().setName('removelist').setDescription('ลบรายชื่อออกจาก List')
.addIntegerOption(opt => opt.setName('number').setDescription('ลำดับที่ต้องการลบ').setRequired(true))
].map(command => command.toJSON());
client.once(Events.ClientReady, async () => {
console.log(`บอทออนไลน์แล้วในชื่อ ${client.user.tag}!`);
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
try {
await rest.put(Routes.applicationCommands(client.user.id), { body: commands });
console.log('✅ ลงทะเบียน Slash Commands สำเร็จแล้ว!');
} catch (error) {
console.error(error);
}
});
client.on('interactionCreate', async interaction => {
if (interaction.isChatInputCommand()) {
if (ADMIN_COMMANDS.includes(interaction.commandName)) {
const hasAdminRole = ADMIN_ROLES_ID.some(roleId => interaction.member.roles.cache.has(roleId));
if (!hasAdminRole) {
return interaction.reply({ content: '❌ คุณไม่มียศที่อนุญาตให้ใช้คำสั่งนี้ได้ครับ!', flags: MessageFlags.Ephemeral });
}
}
if (interaction.commandName === 'ping') await interaction.reply({ content: 'Pong! 🏓', flags: MessageFlags.Ephemeral });
if (interaction.commandName === 'addlist') {
const newName = interaction.options.getString('name');
const position = interaction.options.getInteger('position');
await interaction.reply({ content: `✅ กำลังเพิ่มรายชื่อ **${newName}** ${position ? `แทรกลำดับที่ ${position}` : 'ต่อท้ายลิสต์'}...`, flags: MessageFlags.Ephemeral });
// ✨ บันทึก Log
await sendActionLog(interaction.user, `ใช้คำสั่ง \`/addlist\` เพิ่มชื่อ: **${newName}** (ตำแหน่ง: ${position || 'ท้ายสุด'})`);
await updateKJYList(client, interaction.guild, 'add', newName, position);
}
if (interaction.commandName === 'editlist') {
const editIndex = interaction.options.getInteger('number');
const newName = interaction.options.getString('new_name');
await interaction.reply({ content: `✏️ กำลังแก้ไขลำดับที่ **${editIndex}** เป็นชื่อ **${newName}**...`, flags: MessageFlags.Ephemeral });
// ✨ บันทึก Log
await sendActionLog(interaction.user, `ใช้คำสั่ง \`/editlist\` แก้ไขลำดับที่: **${editIndex}** เป็นชื่อ: **${newName}**`);
await updateKJYList(client, interaction.guild, 'edit', newName, editIndex);
}
if (interaction.commandName === 'removelist') {
const removeIndex = interaction.options.getInteger('number');
await interaction.reply({ content: `🗑️ กำลังลบรายชื่อลำดับที่ **${removeIndex}** ออกจากระบบ...`, flags: MessageFlags.Ephemeral });
// ✨ บันทึก Log
await sendActionLog(interaction.user, `ใช้คำสั่ง \`/removelist\` ลบรายชื่อลำดับที่: **${removeIndex}**`);
await updateKJYList(client, interaction.guild, 'remove', removeIndex);
}
if (interaction.commandName === 'setup') {
const embed = new EmbedBuilder()
.setTitle('แบบฟอร์มสมัครเป็นรุ่นใหญ่ KJY')
.setDescription('KJY GUARANTEE TDED & SECRET')
.setColor('#b800be')
.setImage('https://media.discordapp.net/attachments/1409255795597508648/1473052941425578197/BANNERKJY.png?ex=6994cef5&is=69937d75&hm=699bd1f81ac6074c37af3dd09e487dc6b6d56afcf4c21b8bc3f7826afaa3739e&=&format=webp&quality=lossless');
const applyBtn = new ButtonBuilder().setCustomId('btn_apply_whitelist').setLabel('Join us!!').setStyle(ButtonStyle.Primary).setEmoji(EMOJI_JOIN_BTN);
const row = new ActionRowBuilder().addComponents(applyBtn);
await interaction.channel.send({ embeds: [embed], components: [row] });
await interaction.reply({ content: '✅ สร้างแผงรับสมัครสำเร็จแล้ว!', flags: MessageFlags.Ephemeral });
// ✨ บันทึก Log
await sendActionLog(interaction.user, `ใช้คำสั่ง \`/setup\` สร้างแบบฟอร์มรับสมัคร`);
}
if (interaction.commandName === 'say') {
const userMessage = interaction.options.getString('message');
const memberVoiceChannel = interaction.member.voice.channel;
if (!memberVoiceChannel) {
return interaction.reply({ content: '❌ คุณต้องเข้าไปอยู่ในห้องเสียงก่อนครับ บอทถึงจะตามเข้าไปพูดได้!', flags: MessageFlags.Ephemeral });
}
await interaction.reply({ content: `🗣️ กำลังเข้าไปพูดคำว่า: "${userMessage}"`, flags: MessageFlags.Ephemeral });
// ✨ บันทึก Log
await sendActionLog(interaction.user, `ใช้คำสั่ง \`/say\` สั่งให้บอทพูดว่า: "${userMessage}"`);
try {
const audioUrl = googleTTS.getAudioUrl(userMessage, { lang: 'th', slow: false, host: 'https://translate.google.com' });
const connection = joinVoiceChannel({
channelId: memberVoiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
});
const player = createAudioPlayer();
const resource = createAudioResource(audioUrl);
player.on('error', error => console.error('❌ สาเหตุที่ไม่มีเสียง:', error.message));
player.play(resource);
connection.subscribe(player);
player.on(AudioPlayerStatus.Idle, () => connection.destroy());
} catch (error) {
console.error(error);
await interaction.editReply({ content: '❌ เกิดข้อผิดพลาดในการโหลดเสียงครับ' });
}
}
if (interaction.commandName === 'shake') {
const targetMember = interaction.options.getMember('target');
if (!targetMember || !targetMember.voice.channel) return interaction.reply({ content: '❌ คนนี้ไม่ได้อยู่ในห้องเสียง เขย่าไม่ได้ครับ!', flags: MessageFlags.Ephemeral });
const originalChannel = targetMember.voice.channel;
const voiceChannels = interaction.guild.channels.cache.filter(c => c.type === ChannelType.GuildVoice);
if (voiceChannels.size < 2) return interaction.reply({ content: '❌ เซิร์ฟเวอร์นี้ต้องมีห้องเสียงอย่างน้อย 2 ห้อง ถึงจะสลับสั่นได้ครับ!', flags: MessageFlags.Ephemeral });
const channelsToShake = Array.from(voiceChannels.values()).slice(0, 2);
await interaction.reply({ content: `🌪️ กำลังเขย่า **${targetMember.user.username}** ให้ตื่น!`, flags: MessageFlags.Ephemeral });
// ✨ บันทึก Log
await sendActionLog(interaction.user, `ใช้คำสั่ง \`/shake\` เขย่าผู้ใช้: <@${targetMember.id}>`);
try {
for (let i = 0; i < 6; i++) {
const nextChannel = channelsToShake[i % 2];
await targetMember.voice.setChannel(nextChannel);
await wait(1000);
}
await targetMember.voice.setChannel(originalChannel);
await interaction.followUp({ content: `✅ เขย่าเสร็จแล้ว! ส่งกลับห้องเดิมเรียบร้อย`, flags: MessageFlags.Ephemeral });
} catch (error) {
console.error('เกิดข้อผิดพลาดในการย้ายห้อง:', error);
await interaction.followUp({ content: '❌ เกิดข้อผิดพลาด บอทอาจจะไม่มีสิทธิ์ Move Members ครับ', flags: MessageFlags.Ephemeral });
}
}
}
if (interaction.isButton()) {
if (interaction.customId === 'btn_apply_whitelist') {
const modal = new ModalBuilder().setCustomId('modal_whitelist_form').setTitle('แบบฟอร์มสมัคร KJY');
const fRoblox = new TextInputBuilder().setCustomId('input_roblox').setLabel('Username Roblox').setStyle(TextInputStyle.Short).setRequired(true);
const fOcName = new TextInputBuilder().setCustomId('input_oc_name').setLabel('[OC] ชื่อเล่น').setStyle(TextInputStyle.Short).setRequired(true);
const fAge = new TextInputBuilder().setCustomId('input_age').setLabel('[OC] อายุ').setStyle(TextInputStyle.Short).setRequired(true);
const fIcName = new TextInputBuilder().setCustomId('input_ic_name').setLabel('[IC] ชื่อ-นามสกุล (ENG)').setStyle(TextInputStyle.Short).setRequired(true);
const fSocial = new TextInputBuilder().setCustomId('input_social').setLabel('Social Media (Ig, Fb, Tiktok)').setStyle(TextInputStyle.Paragraph).setRequired(true);
modal.addComponents(
new ActionRowBuilder().addComponents(fRoblox),
new ActionRowBuilder().addComponents(fOcName),
new ActionRowBuilder().addComponents(fAge),
new ActionRowBuilder().addComponents(fIcName),
new ActionRowBuilder().addComponents(fSocial)
);
await interaction.showModal(modal);
}
if (interaction.customId.startsWith('approve_') || interaction.customId.startsWith('reject_')) {
const action = interaction.customId.split('_')[0];
const userId = interaction.customId.split('_')[1];
const oldEmbed = interaction.message.embeds[0];
const newEmbed = EmbedBuilder.from(oldEmbed);
const targetMember = await interaction.guild.members.fetch(userId).catch(() => null);
if (action === 'approve') {
newEmbed.setColor('#2ecc71');
newEmbed.setAuthor(null);
newEmbed.setTitle(`✅ [อนุมัติแล้ว] ${oldEmbed.title ? oldEmbed.title.replace('ใบสมัครใหม่จาก: ', '') : userId}`);
newEmbed.setFooter({ text: `ตรวจสอบโดย: ${interaction.user.tag}` });
await interaction.update({ embeds: [newEmbed], components: [] });
// ✨ บันทึก Log การกดอนุมัติ
await sendActionLog(interaction.user, `กดปุ่ม **อนุมัติ (ผ่าน)** ให้กับใบสมัครของ <@${userId}>`);
if (targetMember) {
await targetMember.roles.add(ROLE_APPROVED_ID).catch(console.error);
await targetMember.roles.remove(ROLE_PENDING_ID).catch(console.error);
}
const getField = (name) => oldEmbed.fields.find(f => f.name.includes(name))?.value || '-';
const listRoblox = getField('Roblox');
const listIC = getField('ชื่อ-สกุล');
await updateKJYList(client, interaction.guild, 'add', `${listIC} (${listRoblox})`);
const announceChannel = interaction.client.channels.cache.get(ANNOUNCE_CHANNEL_ID);
if (announceChannel && targetMember) {
const publicEmbed = new EmbedBuilder()
.setTitle('🎉 ต้อนรับหมูตัวใหม่หน่อยเร๊ววว')
.addFields(
{ name: '🎮 Roblox', value: listRoblox, inline: true },
{ name: '💬 [OC] ชื่อเล่น', value: getField('ชื่อเล่น'), inline: true },
{ name: '🎂 [OC] อายุ', value: getField('อายุ'), inline: true },
{ name: '🏷️ [IC] ชื่อ-สกุล (ENG)', value: listIC, inline: false },
{ name: '🔗 Social Media', value: getField('Social Media'), inline: false }
)
.setColor('#ff9ff3')
.setThumbnail(targetMember.user.displayAvatarURL({ dynamic: true, size: 512 }));
const pingText = ROLE_TO_PING_ID === '@everyone' || ROLE_TO_PING_ID === '@here' ? ROLE_TO_PING_ID : `<@&${ROLE_TO_PING_ID}>`;
await announceChannel.send({ content: `เอ๊ะ!! มีหมูหลุดเข้ารั้ว KJY มาหนึ่งตัว 🐽🐽 ${pingText} !`, embeds: [publicEmbed] });
}
} else if (action === 'reject') {
newEmbed.setColor('#e74c3c');
newEmbed.setAuthor(null);
newEmbed.setTitle(`❌ [ปฏิเสธ] ${oldEmbed.title ? oldEmbed.title.replace('ใบสมัครใหม่จาก: ', '') : userId}`);
newEmbed.setFooter({ text: `ตรวจสอบโดย: ${interaction.user.tag}` });
await interaction.update({ embeds: [newEmbed], components: [] });
// ✨ บันทึก Log การกดปฏิเสธ
await sendActionLog(interaction.user, `กดปุ่ม **ปฏิเสธ (ไม่ผ่าน)** ให้กับใบสมัครของ <@${userId}>`);
if (targetMember) {
await targetMember.roles.remove(ROLE_PENDING_ID).catch(console.error);
}
}
}
}
if (interaction.isModalSubmit()) {
if (interaction.customId === 'modal_whitelist_form') {
const roblox = interaction.fields.getTextInputValue('input_roblox');
const ocName = interaction.fields.getTextInputValue('input_oc_name');
const age = interaction.fields.getTextInputValue('input_age');
const icName = interaction.fields.getTextInputValue('input_ic_name');
const social = interaction.fields.getTextInputValue('input_social');
if (interaction.member) {
await interaction.member.roles.add(ROLE_PENDING_ID).catch(console.error);
}
await interaction.reply({ content: '✅ ส่งใบสมัครเรียบร้อย ได้รับยศ "รอตรวจสอบ" แล้ว รอรุ่นใหญ่ตรวจสักครู่นะครับ!', flags: MessageFlags.Ephemeral });
const logChannel = interaction.client.channels.cache.get(LOG_CHANNEL_ID);
if (!logChannel) return console.error('หาระบบห้อง Log ไม่เจอ');
const logEmbed = new EmbedBuilder()
.setTitle(`ใบสมัครใหม่จาก: ${interaction.user.username}`)
.setThumbnail(interaction.user.displayAvatarURL({ dynamic: true, size: 512 }))
.addFields(
{ name: '👤 ผู้สมัคร (Discord)', value: `<@${interaction.user.id}>` },
{ name: '🎮 Username Roblox', value: roblox, inline: true },
{ name: '💬 [OC] ชื่อเล่น', value: ocName, inline: true },
{ name: '🎂 [OC] อายุ', value: age, inline: true },
{ name: '🏷️ [IC] ชื่อ-สกุล (ENG)', value: icName, inline: false },
{ name: '🔗 Social Media', value: social, inline: false }
)
.setColor('#f1c40f')
.setTimestamp();
const btnApprove = new ButtonBuilder().setCustomId(`approve_${interaction.user.id}`).setLabel('ผ่าน').setStyle(ButtonStyle.Success).setEmoji(EMOJI_APPROVE_BTN);
const btnReject = new ButtonBuilder().setCustomId(`reject_${interaction.user.id}`).setLabel('ไม่ผ่าน').setStyle(ButtonStyle.Danger).setEmoji(EMOJI_REJECT_BTN);
const logRow = new ActionRowBuilder().addComponents(btnApprove, btnReject);
await logChannel.send({ embeds: [logEmbed], components: [logRow] });
}
}
});
client.login(process.env.TOKEN);