Selamlar ,
Discord için mesaj botu yaptırmak istiyoruz.
İçeriği ;
SQL tablolar içerisinde yeni bir sorgu çalıştıracak ve bu sorgudan aldığı sonucu discord kanalında mesaj olarak atacak.
Sorguları SQL veri tabanında bir Tabloya yazacak ve bu tabloya eklenen her yeni Column discord kanalına yazılacak.
Discord Botu Yaptırılacaktır.
2
●124
- 04-09-2024, 13:56:30test edilmedi
const mysql = require('mysql2'); const { Client, GatewayIntentBits } = require('discord.js'); // MySQL bağlantısı const db = mysql.createConnection({ host: 'localhost', user: 'root', password: 'your_password', database: 'your_database' }); // Discord botu için istemci oluşturma const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] }); const DISCORD_TOKEN = 'your_discord_bot_token'; const CHANNEL_ID = 'your_discord_channel_id'; const TABLE_NAME = 'your_table_name'; // Daha önceki kolonları saklamak için bir dizi let previousColumns = []; // Bot çalıştığında yapılacak işlemler client.once('ready', () => { console.log('Bot is online!'); // SQL tablo yapısını düzenli olarak kontrol et setInterval(() => { db.query(`SHOW COLUMNS FROM ${TABLE_NAME}`, (err, columns) => { if (err) throw err; const columnNames = columns.map(col => col.Field); // Yeni eklenen kolonları tespit et const newColumns = columnNames.filter(col => !previousColumns.includes(col)); if (newColumns.length > 0) { newColumns.forEach(column => { db.query(`SELECT ${column} FROM ${TABLE_NAME}`, (err, results) => { if (err) throw err; // Kolonun verisini discord kanalına gönder results.forEach(row => { const message = `Yeni Kolon Eklendi: **${column}**nDeğerler:n${Object.values(row).join('n')}`; client.channels.cache.get(CHANNEL_ID).send(message); }); }); }); // Güncellenmiş kolon listesini sakla previousColumns = columnNames; } }); }, 5000); // 5 saniyede bir tabloyu kontrol et }); client.login(DISCORD_TOKEN);