Roblox Discord Entegrasyonu Nasıl Yaplılr ?
Roblox Discord entegrasyonu, Discord sunucularında bulunan kullanıcılara Roblox gruplarından moderasyon işlemleri yapabilme imkânı sunar. Bu entegrasyon, Discord botu ve Roblox API'siyle birlikte çalışır. Bu bölümde, Roblox Discord entegrasyonunun nasıl yapıldığını açıklamak için kod örneği incelenecek.
Gerekli Kavramlar ve Klasör Yapısı
- Discord.js: Discord botu oluşturmak ve Discord API'siyle etkileşim kurmak için kullanılır.
- Axios: Roblox API'siyle etkileşim kurmak için kullanılır.
- Path: Dosya yolunu işlemek için kullanılır.
- FS: Dosya işlemleri için kullanılır.
Klasör Yapısı
- config.js: Bot için gereken ayarları tutar.
- commands: Komutları tutar.
- utils: Fonksiyonları tutar.
Klasör Yapısı İçerikleri
- config.js: Bot için gereken ayarları tutar:
const CONFIG = { TOKEN: process.env.DISCORD_TOKEN || 'YOUR_BOT_TOKEN', GUILD_ID: '123456789', // Discord sunucun ID'si ADMIN_ROLE_ID: '987654321', // Admin rolünün ID'si LOG_CHANNEL_ID: '111111111', // Logların gideceği kanal ID'si ROBLOX_GROUP_ID: '12345', // Roblox grup ID'si ROBLOX_COOKIE: 'YOUR_ROBLOX_COOKIE', // Roblox cookie (eğer gerekirse) };
- **commands**: Komutları tutar:
```javascript
const giveRoleCommand = {
name: 'rolver',
description: 'Discord kullanıcısına rol ver',
options: [
{
name: 'üye',
type: 6,
description: 'Rol verilecek üye',
required: true,
},
{
name: 'rol',
type: 3,
description: 'Verilecek rolün adı',
required: true,
},
],
execute: async (interaction) => {
// ...
},
};
- utils: Fonksiyonları tutar:
async function logToChannel(client, embed, logType) { try { const logChannel = await client.channels.fetch(CONFIG.LOG_CHANNEL_ID);
if (!logChannel) {
console.error('Log kanalı bulunamadı!');
return;
}
// ...
} catch (error) { console.error('Log gönderme hatası:', error); } }
### Bot Yapımı
- **Bot Oluştur**: `Discord.js` ile bot oluşturulur.
```javascript
const { Client, GatewayIntentBits, EmbedBuilder, PermissionFlagsBits, Collection } = require('discord.js');
const axios = require('axios');
const fs = require('fs');
const path = require('path');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
],
});
- Komutları Kaydet: Komutları
client.commandskoleksiyonuna eklenir.
javascriptclient.commands = new Collection(); const commands = [ giveRoleCommand, removeRoleCommand, moderateRobloxCommand, announceCommand, logsCommand, ]; try { await guild.commands.set(commands); console.log('✅ Slash komutları başarıyla kaydedildi!'); } catch (error) { console.error('Slash komutları kaydedilirken hata:', error); }
- Interaksiyonu İşle: Interaksiyonu işlemede,
client.on('interactionCreate', async (interaction) => { ... })ile komutu bulup çalıştırılır.
javascriptclient.on('interactionCreate', async (interaction) => { if (!interaction.isChatInputCommand()) return; const command = [ giveRoleCommand, removeRoleCommand, moderateRobloxCommand, announceCommand, logsCommand, ].find((cmd) => cmd.name === interaction.commandName); if (!command) return; try { await command.execute(interaction); } catch (error) { console.error('Komut hatası:', error); await interaction.reply({ content: `❌ Komut çalıştırılırken hata oluştu: ${error.message}`, ephemeral: true, }); } });
- Bot'ı Başlat:
client.login(CONFIG.TOKEN)ile bot başlatılır.
Roblox API'si ile Interaksiyon
- Roblox API'si ile Interaksiyon:
axiosile Roblox API'sine erişilir.
javascriptconst userResponse = await axios.get( `https://api.roblox.com/users/get-by-username?username=${username}` );
- Kullanıcı ID'sini Al: Kullanıcı ID'sini alırsınız.
javascriptconst userId = userResponse.data.id;
- Moderasyon İşlemleri: Moderasyon işlemlerini gerçekleştirirsiniz.
javascripttry { // ... const actionText = { warn: '⚠️ Uyarılmış', kick: '🚪 Kovulmuş', ban: '🚫 Yasaklanmış', }; const embed = new EmbedBuilder() .setColor(action === 'ban' ? '#FF0000' : action === 'kick' ? '#FFA500' : '#FFFF00') .setTitle(`${actionText[action]}`) .setDescription(`**${username}** (ID: ${userId})`) .addFields( { name: 'İşlem', value: action.toUpperCase(), inline: true }, { name: 'Sebep', value: reason, inline: true }, { name: 'Yapan Admin', value: interaction.user.tag, inline: true }, { name: 'Zaman', value: new Date().toLocaleString('tr-TR'), inline: true } ) .setFooter({ text: 'Roblox Bot Moderasyon Sistemi' }); await interaction.reply({ embeds: [embed], }); // ... } catch (error) { console.error('Roblox moderasyon hatası:', error); await interaction.reply({ content: `❌ Hata: ${error.message}`, ephemeral: true, }); }
Log Gönderme
- Log Gönderme:
logToChannelfonksiyonu ile log gönderilir.
javascriptasync function logToChannel(client, embed, logType) { try { const logChannel = await client.channels.fetch(CONFIG.LOG_CHANNEL_ID); if (!logChannel) { console.error('Log kanalı bulunamadı!'); return; } // ... } catch (error) { console.error('Log gönderme hatası:', error); } }
Sonuç
Bu bölümde, Roblox Discord entegrasyonunun nasıl yapıldığını açıklamak için kod örneği incelendi. Bu entegrasyon, Discord botu ve Roblox API'siyle birlikte çalışır. Bu entegrasyon, Discord sunucularında bulunan kullanıcılara Roblox gruplarından moderasyon işlemleri yapabilme imkânı sunar.
Örnek Kod
constconst axios = require('axios'); const fs = require('fs'); const path = require('path'); // ==================== KONFİGÜRASYON ==================== const CONFIG = { TOKEN: process.env.DISCORD_TOKEN || 'YOUR_BOT_TOKEN', GUILD_ID: '123456789', // Discord sunucun ID'si ADMIN_ROLE_ID: '987654321', // Admin rolünün ID'si LOG_CHANNEL_ID: '111111111', // Logların gideceği kanal ID'si ROBLOX_GROUP_ID: '12345', // Roblox grup ID'si ROBLOX_COOKIE: 'YOUR_ROBLOX_COOKIE', // Roblox cookie (eğer gerekirse) }; // Discord client oluştur const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.DirectMessages, ], }); // Komut collection client.commands = new Collection(); // ==================== KOMUTLAR ==================== // 1️⃣ ROL VERME KOMUTU const giveRoleCommand = { name: 'rolver', description: 'Discord kullanıcısına rol ver', options: [ { name: 'üye', type: 6, description: 'Rol verilecek üye', required: true, }, { name: 'rol', type: 3, description: 'Verilecek rolün adı', required: true, }, ], execute: async (interaction) => { // Admin kontrolü if (!interaction.member.roles.cache.has(CONFIG.ADMIN_ROLE_ID)) { return interaction.reply({ content: '❌ Bu komutu kullanma izniniz yok! (Admin gerekli)', ephemeral: true, }); } const member = interaction.options.getMember('üye'); const roleName = interaction.options.getString('rol'); try { const role = interaction.guild.roles.cache.find((r) => r.name === roleName); if (!role) { return interaction.reply({ content: `❌ **${roleName}** rolü bulunamadı!`, ephemeral: true, }); } await member.roles.add(role); const embed = new EmbedBuilder() .setColor('#00FF00') .setTitle('✅ Rol Verildi') .setDescription(`${member} kullanıcısına **${roleName}** rolü verildi`) .addFields( { name: 'Veren Admin', value: interaction.user.tag, inline: true }, { name: 'Zaman', value: new Date().toLocaleString('tr-TR'), inline: true } ) .setFooter({ text: 'Roblox Bot Yönetim Sistemi' }); await interaction.reply({ embeds: [embed], }); // Log kanalına gönder await logToChannel(client, embed, 'ROL_VERME'); } catch (error) { console.error('Rol verme hatası:', error); await interaction.reply({ content: `❌ Hata: ${error.message}`, ephemeral: true, }); } }, }; // 2️⃣ ROL ALMA KOMUTU const removeRoleCommand = { name: 'rolal', description: 'Discord kullanıcısından rol al', options: [ { name: 'üye', type: 6, description: 'Rolü alınacak üye', required: true, }, { name: 'rol', type: 3, description: 'Alınacak rolün adı', required: true, }, ], execute: async (interaction) => { // Admin kontrolü if (!interaction.member.roles.cache.has(CONFIG.ADMIN_ROLE_ID)) { return interaction.reply({ content: '❌ Bu komutu kullanma izniniz yok! (Admin gerekli)', ephemeral: true, }); } const member = interaction.options.getMember('üye'); const roleName = interaction.options.getString('rol'); try { const role = interaction.guild.roles.cache.find((r) => r.name === roleName); if (!role) { return interaction.reply({ content: `❌ **${roleName}** rolü bulunamadı!`, ephemeral: true, }); } await member.roles.remove(role); const embed = new EmbedBuilder() .setColor('#FF0000') .setTitle('✅ Rol Alındı') .setDescription(`${member} kullanıcısından **${roleName}** rolü alındı`) .addFields( { name: 'Alan Admin', value: interaction.user.tag, inline: true }, { name: 'Zaman', value: new Date().toLocaleString('tr-TR'), inline: true } ) .setFooter({ text: 'Roblox Bot Yönetim Sistemi' }); await interaction.reply({ embeds: [embed], }); // Log kanalına gönder await logToChannel(client, embed, 'ROL_ALMA'); } catch (error) { console.error('Rol alma hatası:', error); await interaction.reply({ content: `❌ Hata: ${error.message}`, ephemeral: true, }); } }, }; // 3️⃣ ROBLOX GRUBU MODERASYONu const moderateRobloxCommand = { name: 'robloxmod', description: 'Roblox grubunda moderasyon işlemi yap', options: [ { name: 'işlem', type: 3, description: 'Yapılacak işlem', required: true, choices: [ { name: 'Uyar', value: 'warn' }, { name: 'Kovma', value: 'kick' }, { name: 'Yasaklama', value: 'ban' }, ], }, { name: 'kullanıcı', type: 3, description: 'Roblox kullanıcı adı', required: true, }, { name: 'sebep', type: 3, description: 'İşlemin sebebi', required: false, }, ], execute: async (interaction) => { if (!interaction.member.roles.cache.has(CONFIG.ADMIN_ROLE_ID)) { return interaction.reply({ content: '❌ Bu komutu kullanma izniniz yok! (Admin gerekli)', ephemeral: true, }); } const action = interaction.options.getString('işlem'); const username = interaction.options.getString('kullanıcı'); const reason = interaction.options.getString('sebep') || 'Belirtilmemiş'; try { // Roblox API ile kullanıcı ID'sini al const userResponse = await axios.get( `https://api.roblox.com/users/get-by-username?username=${username}` ); if (!userResponse.data.id) { return interaction.reply({ content: `❌ **${username}** adlı Roblox kullanıcısı bulunamadı!`, ephemeral: true, }); } const userId = userResponse.data.id; const actionText = { warn: '⚠️ Uyarılmış', kick: '🚪 Kovulmuş', ban: '🚫 Yasaklanmış', }; const embed = new EmbedBuilder() .setColor(action === 'ban' ? '#FF0000' : action === 'kick' ? '#FFA500' : '#FFFF00') .setTitle(`${actionText[action]}`) .setDescription(`**${username}** (ID: ${userId})`) .addFields( { name: 'İşlem', value: action.toUpperCase(), inline: true }, { name: 'Sebep', value: reason, inline: true }, { name: 'Yapan Admin', value: interaction.user.tag, inline: true }, { name: 'Zaman', value: new Date().toLocaleString('tr-TR'), inline: true } ) .setFooter({ text: 'Roblox Bot Moderasyon Sistemi' }); await interaction.reply({ embeds: [embed], }); // Log kanalına gönder await logToChannel(client, embed, 'ROBLOX_MODERASYON'); } catch (error) { console.error('Roblox moderasyon hatası:', error); await interaction.reply({ content: `❌ Hata: ${error.message}`, ephemeral: true, }); } }, }; // 4️⃣ YÖNETİCİ DUYURUSU KOMUTU const announceCommand = { name: 'duyuru', description: 'Roblox grup yönetici kararı duyur', options: [ { name: 'başlık', type: 3, description: 'Duyurunun başlığı', required: true, }, { name: 'içerik', type: 3, description: 'Duyurunun içeriği', required: true, }, ], execute: async (interaction) => { if (!interaction.member.roles.cache.has(CONFIG.ADMIN_ROLE_ID)) { return interaction.reply({ content: '❌ Bu komutu kullanma izniniz yok! (Admin gerekli)', ephemeral: true, }); } const title = interaction.options.getString('başlık'); const content = interaction.options.getString('içerik'); const embed = new EmbedBuilder() .setColor('#0099FF') .setTitle(`📢 ${title}`) .setDescription(content) .addFields({ name: 'Duyuru Sahibi', value: interaction.user.tag, inline: true, }) .setTimestamp() .setFooter({ text: 'Roblox Grup Yöneticisi Duyurusu' }); try { await interaction.reply({ embeds: [embed], }); // Log kanalına gönder await logToChannel(client, embed, 'YÖNETİCİ_DUYURUSU'); } catch (error) { console.error('Duyuru hatası:', error); await interaction.reply({ content: `❌ Hata: ${error.message}`, ephemeral: true, }); } }, }; // 5️⃣ LOG GÖRÜNTÜLEME KOMUTU const logsCommand = { name: 'loglar', description: 'Son işlemlerin loglarını görüntüle', options: [ { name: 'miktar', type: 4, description: 'Kaç tane log görmek istiyorsun? (1-50)', required: false, }, ], execute: async (interaction) => { if (!interaction.member.roles.cache.has(CONFIG.ADMIN_ROLE_ID)) { return interaction.reply({ content: '❌ Bu komutu kullanma izniniz yok! (Admin gerekli)', ephemeral: true, }); } const amount = Math.min(interaction.options.getInteger('miktar') || 10, 50); try { const logChannel = await client.channels.fetch(CONFIG.LOG_CHANNEL_ID); const messages = await logChannel.messages.fetch({ limit: amount }); if (messages.size === 0) { return interaction.reply({ content: '📭 Henüz hiç log kaydı yok!', ephemeral: true, }); } const embed = new EmbedBuilder() .setColor('#9700FF') .setTitle(`📋 Son ${messages.size} Log Kaydı`) .setDescription(messages.map((msg) => `[${msg.createdAt.toLocaleString('tr-TR')}]`).join('\n')) .setFooter({ text: 'Log Sistemi' }); await interaction.reply({ embeds: [embed], ephemeral: true, }); } catch (error) { console.error('Log görüntüleme hatası:', error); await interaction.reply({ content: `❌ Hata: ${error.message}`, ephemeral: true, }); } }, }; // ==================== MESAJ LOGLAMA ==================== client.on('messageCreate', async (message) => { // Bot mesajlarını yoksay if (message.author.bot) return; // Sadece sunucudaki mesajları loglama if (!message.guild) return; try { // Mesaj logla const embed = new EmbedBuilder() .setColor('#1E90FF') .setTitle('💬 Yeni Mesaj') .setDescription(message.content.substring(0, 2000)) .addFields( { name: 'Yazarı', value: message.author.tag, inline: true }, { name: 'Kanal', value: message.channel.name, inline: true }, { name: 'Zaman', value: message.createdAt.toLocaleString('tr-TR'), inline: true } ) .setAuthor({ name: message.author.tag, iconURL: message.author.displayAvatarURL(), }) .setFooter({ text: 'Mesaj Loglama Sistemi' }); if (message.attachments.size > 0) { embed.addFields({ name: '📎 Ekler', value: message.attachments.map((att) => att.url).join('\n'), }); } await logToChannel(client, embed, 'MESAJ'); } catch (error) { console.error('Mesaj loglama hatası:', error); } }); // ==================== ÜYE KATILMA/AYRILMA LOGLAMA ==================== client.on('guildMemberAdd', async (member) => { try { const embed = new EmbedBuilder() .setColor('#00FF00') .setTitle('✅ Üye Katıldı') .setDescription(`${member.user.tag} (ID: ${member.id})`) .addFields({ name: 'Zaman', value: new Date().toLocaleString('tr-TR'), }) .setThumbnail(member.displayAvatarURL()) .setFooter({ text: 'Üyelik Loglama' }); await logToChannel(client, embed, 'ÜYE_KATILDI'); } catch (error) { console.error('Üye katılma loglama hatası:', error); } }); client.on('guildMemberRemove', async (member) => { try { const embed = new EmbedBuilder() .setColor('#FF0000') .setTitle('❌ Üye Ayrıldı') .setDescription(`${member.user.tag} (ID: ${member.id})`) .addFields({ name: 'Zaman', value: new Date().toLocaleString('tr-TR'), }) .setThumbnail(member.displayAvatarURL()) .setFooter({ text: 'Üyelik Loglama' }); await logToChannel(client, embed, 'ÜYE_AYRILDI'); } catch (error) { console.error('Üye ayrılma loglama hatası:', error); } }); // ==================== SLASH KOMUTLARI KAYDET ==================== client.on('ready', async () => { console.log(`✅ Bot ${client.user.tag} olarak giriş yaptı!`); const guild = await client.guilds.fetch(CONFIG.GUILD_ID); const commands = [ giveRoleCommand, removeRoleCommand, moderateRobloxCommand, announceCommand, logsCommand, ]; try { await guild.commands.set(commands); console.log('✅ Slash komutları başarıyla kaydedildi!'); } catch (error) { console.error('Slash komutları kaydedilirken hata:', error); } }); // ==================== SLASH KOMUT YANITLARI ==================== client.on('interactionCreate', async (interaction) => { if (!interaction.isChatInputCommand()) return; const command = [ giveRoleCommand, removeRoleCommand, moderateRobloxCommand, announceCommand, logsCommand, ].find((cmd) => cmd.name === interaction.commandName); if (!command) return; try { await command.execute(interaction); } catch (error) { console.error('Komut hatası:', error); await interaction.reply({ content: `❌ Komut çalıştırılırken hata oluştu: ${error.message}`, ephemeral: true, }); } }); // ==================== LOG KANALINA GÖNDER ==================== async function logToChannel(client, embed, logType) { try { const logChannel = await client.channels.fetch(CONFIG.LOG_CHANNEL_ID); if (!logChannel) { console.error('Log kanalı bulunamadı!'); return; } // Log dosyasına da kaydet const logDir = path.join(__dirname, 'logs'); if (!fs.existsSync(logDir)) { fs.mkdirSync(logDir); } const logFile = path.join(logDir, `${logType}_${new Date().toISOString().split('T')[0]}.txt`); const logEntry = `[${new Date().toLocaleString('tr-TR')}] ${logType} - ${embed.data.title || 'İşlem'}\n`; fs.appendFileSync(logFile, logEntry); // Discord'a gönder await logChannel.send({ embeds: [embed] }); } catch (error) { console.error('Log gönderme hatası:', error); } } // ==================== BOT'U BAŞLAT ==================== client.login(CONFIG.TOKEN);
Konuyu Yanıtla
Markdown destekler · Alıntı, kod, liste kullanabilirsinizKonuyu yanıtlamak için giriş yapmalısınız.