| |
| |
| |
| |
|
|
| const { |
| Client, |
| GatewayIntentBits, |
| Partials, |
| PermissionFlagsBits, |
| SlashCommandBuilder, |
| REST, |
| Routes |
| } = require('discord.js'); |
| const fs = require('fs'); |
| const path = require('path'); |
| const express = require('express'); |
|
|
| |
| const app = express(); |
| app.get('/', (req, res) => res.send('Bot Sistemi Aktif ve Güvende!')); |
| app.listen(7860, () => console.log('✅ Sistem Port 7860 üzerinden yayında.')); |
|
|
| |
| |
| const TOKEN = process.env.DISCORD_TOKEN; |
| const CLIENT_ID = '1477703339612311685'; |
|
|
| const client = new Client({ |
| intents: [ |
| GatewayIntentBits.Guilds, |
| GatewayIntentBits.GuildMessages, |
| GatewayIntentBits.MessageContent, |
| GatewayIntentBits.GuildMembers |
| ], |
| partials: [Partials.Message, Partials.Channel, Partials.Reaction] |
| }); |
|
|
| const dbPath = path.join(__dirname, 'triggers.json'); |
| if (!fs.existsSync(dbPath)) fs.writeFileSync(dbPath, JSON.stringify({})); |
| let triggers = JSON.parse(fs.readFileSync(dbPath, 'utf8')); |
|
|
| |
| function parseVariables(content, message) { |
| const now = new Date(); |
| const timeStr = now.toLocaleTimeString('tr-TR', { hour: '2-digit', minute: '2-digit' }); |
| const dateStr = now.toLocaleDateString('tr-TR'); |
| return content |
| .replace(/!user/g, `<@${message.author.id}>`) |
| .replace(/!time/g, timeStr) |
| .replace(/!date/g, dateStr) |
| .replace(/!sw/g, message.guild.name); |
| } |
|
|
| |
| const commands = [ |
| new SlashCommandBuilder() |
| .setName('tetikekle') |
| .setDescription('Yeni bir otomatik yanıt ekler.') |
| .addStringOption(o => o.setName('tetik').setDescription('Tetikleyici kelime').setRequired(true)) |
| .addStringOption(o => o.setName('cevap').setDescription('Botun vereceği cevap').setRequired(true)) |
| .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) |
| ].map(c => c.toJSON()); |
|
|
| const rest = new REST({ version: '10' }).setToken(TOKEN); |
|
|
| |
| async function registerCommands() { |
| if (!TOKEN) return console.error("❌ HATA: DISCORD_TOKEN bulunamadı! Settings -> Secrets kısmına ekle."); |
| try { |
| console.log('🔄 Slash komutları yüklenmeye çalışılıyor...'); |
| await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands }); |
| console.log('✅ Slash komutları başarıyla kaydedildi.'); |
| } catch (error) { |
| console.error('❌ Bağlantı hatası! 15 saniye sonra tekrar denenecek...'); |
| setTimeout(registerCommands, 15000); |
| } |
| } |
|
|
| registerCommands(); |
|
|
| client.once('ready', () => { |
| console.log(`🚀 ${client.user.tag} olarak giriş yapıldı!`); |
| }); |
|
|
| client.on('interactionCreate', async interaction => { |
| if (!interaction.isChatInputCommand()) return; |
| if (interaction.commandName === 'tetikekle') { |
| const tetik = interaction.options.getString('tetik').toLowerCase(); |
| const cevap = interaction.options.getString('cevap'); |
| triggers[tetik] = cevap; |
| fs.writeFileSync(dbPath, JSON.stringify(triggers, null, 4)); |
| await interaction.reply({ content: `✅ Tetik başarıyla eklendi: **${tetik}**`, ephemeral: true }); |
| } |
| }); |
|
|
| client.on('messageCreate', async message => { |
| if (message.author.bot || !message.guild) return; |
| const content = message.content.toLowerCase(); |
| if (triggers[content]) { |
| try { |
| await message.reply(parseVariables(triggers[content], message)); |
| } catch (err) { |
| console.error('Mesaj hatası:', err); |
| } |
| } |
| }); |
|
|
| |
| function startBot() { |
| if (!TOKEN) return; |
| client.login(TOKEN).catch(() => { |
| console.error("❌ Discord'a bağlanılamadı, internet bekleniyor (20sn)..."); |
| setTimeout(startBot, 20000); |
| }); |
| } |
|
|
| startBot(); |