require('dotenv').config(); const { Client, GatewayIntentBits, Partials, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers ], partials: [Partials.Message, Partials.Channel, Partials.GuildMember] }); // AYARLAR const TALEP_KANAL_ID = '1505077283679895612'; // Mesajların yazılacağı kanalın ID'si const YETKILI_ROL_ID = '1504841086559064246'; // Sadece bu role sahip olanlar butonları kullanabilir client.on('ready', () => { console.log(`${client.user.tag} başarıyla aktif edildi ve 7/24 sistemde!`); }); // Kanala mesaj yazıldığında tetiklenecek olay client.on('messageCreate', async (message) => { // Mesajı yazan bot ise veya mesaj başka kanala yazıldıysa hiçbir şey yapma if (message.author.bot || message.channel.id !== TALEP_KANAL_ID) return; const istenenIsim = message.content; // Discord isim sınırı 32 karakterdir, koruma önlemi: if (istenenIsim.length > 32) { const uyari = await message.channel.send(`${message.author}, Discord kuralları gereği isim en fazla 32 karakter olabilir.`); setTimeout(() => uyari.delete(), 5000); // Uyarıyı 5 saniye sonra sil await message.delete().catch(() => {}); return; } // Kullanıcının attığı saf yazıyı sil await message.delete().catch(() => {}); // Talebi şık bir embed haline getir const embed = new EmbedBuilder() .setTitle('Kimlik Yenileme Talebi') .setColor('#2b2d31') // Kurumsal, Discord arkaplanına uygun dark renk .setDescription(`<@${message.author.id}> isimli kullanıcı yeni bir ad soyad talebinde bulundu.\n\nİstenen İsim: **${istenenIsim}**`) .setThumbnail(message.author.displayAvatarURL({ dynamic: true })) .setTimestamp(); // Onay ve Ret butonları const buttons = new ActionRowBuilder().addComponents( new ButtonBuilder() .setCustomId(`onay_${message.author.id}_${istenenIsim}`) .setLabel('Onayla') .setStyle(ButtonStyle.Success), new ButtonBuilder() .setCustomId(`ret_${message.author.id}`) .setLabel('Reddet') .setStyle(ButtonStyle.Danger) ); // Butonlu menüyü kanala gönder await message.channel.send({ embeds: [embed], components: [buttons] }); }); // Yetkili butonlara tıkladığında tetiklenecek olay client.on('interactionCreate', async (interaction) => { if (!interaction.isButton()) return; // YETKİ KONTROLÜ: Tıklayan kişide o rol var mı? if (!interaction.member.roles.cache.has(YETKILI_ROL_ID)) { return interaction.reply({ content: 'Bu talebi onaylamak veya reddetmek için yetkiniz bulunmuyor.', ephemeral: true }); } const [islem, hedefKullaniciId, ...isimParcalari] = interaction.customId.split('_'); const yeniIsim = isimParcalari.join('_'); // İsimde boşluk yerine alt tire kullananlar için birleştirme try { const uye = await interaction.guild.members.fetch(hedefKullaniciId); if (islem === 'onay') { await uye.setNickname(yeniIsim); // İsmi değiştir const basariliEmbed = new EmbedBuilder() .setColor('Green') .setDescription(`✅ <@${hedefKullaniciId}> adlı kullanıcının ismi **${yeniIsim}** olarak onaylandı.\nYetkili: <@${interaction.user.id}>`); await interaction.update({ embeds: [basariliEmbed], components: [] }); } else if (islem === 'ret') { const retEmbed = new EmbedBuilder() .setColor('Red') .setDescription(`❌ <@${hedefKullaniciId}> adlı kullanıcının isim talebi reddedildi.\nYetkili: <@${interaction.user.id}>`); await interaction.update({ embeds: [retEmbed], components: [] }); } } catch (error) { // Eğer botun rolü kullanıcının rolünden alttaysa isim değiştiremez ve bu hata mesajını verir. await interaction.reply({ content: '⚠️ Hata! İsmi değiştiremedim. Botun rolünü sunucu ayarlarından en üste taşıdığınıza emin olun.', ephemeral: true }); } }); client.login(process.env.TOKEN);