Merhaba arkadaşlar, botuma sistem toplayana kadar telefona kurdum. Amacım 7/24 çalışmasını sağlamaktı ancak 7/23 çalışıyor
Şaka bir yana bazen tam gün giderken bazen hata verip çöküyor. Genellikle "Unknown Interaction" hatası geliyor. Index dosyam aşağıda. Botu çalıştırmak için Termux kullanıyorum, ekran kilidi yok telefonda. Ve kablosuz internetle çalışıyor.
JavaScript:
const fs = require('fs');
const path = require('path');
const { Client, GatewayIntentBits, Collection, EmbedBuilder } = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v10');
const moment = require('moment-timezone');
const config = require('./config.json');
// Bot istemcisi
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
]
});
// Koleksiyonlar
client.afkUsers = new Collection();
client.slashCommands = new Collection();
// Slash komutları yükle
const slashCommandFiles = fs.readdirSync(path.join(__dirname, 'slashCommands')).filter(file => file.endsWith('.js'));
const slashCommandsData = [];
for (const file of slashCommandFiles) {
const command = require(`./slashCommands/${file}`);
client.slashCommands.set(command.data.name, command);
slashCommandsData.push(command.data.toJSON());
}
// Slash komutları Discord API'ye kaydet
client.once('ready', async () => {
console.log(` Bot ${client.user.tag} olarak giriş yaptı!`);
const rest = new REST({ version: '10' }).setToken(config.token);
try {
console.log(' Slash komutlar yükleniyor...');
await rest.put(
Routes.applicationCommands(client.user.id),
{ body: slashCommandsData }
);
console.log(' Slash komutlar başarıyla yüklendi!');
} catch (error) {
console.error(' Slash komut yükleme hatası:', error);
}
});
// Slash komut interaction'ı dinle
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.slashCommands.get(interaction.commandName);
if (!command) {
if (!interaction.replied && !interaction.deferred) {
await interaction.reply({ content: '❌ Komut bulunamadı.', ephemeral: true }).catch(() => {});
}
return;
}
try {
await command.execute(interaction, client);
} catch (error) {
console.error(`❌ [${interaction.commandName}] komut hatası:`, error);
if (interaction.replied || interaction.deferred) {
await interaction.editReply({ content: '❌ Bir hata oluştu.' }).catch(() => {});
} else {
await interaction.reply({ content: '❌ Bir hata oluştu.', ephemeral: true }).catch(() => {});
}
}
});
// Mesaj olayını dinle (AFK kontrol ve otomatik yanıtlar)
client.on('messageCreate', async message => {
if (message.author.bot) return;
// AFK'dan çıkarma işlemi
const afkData = client.afkUsers.get(message.author.id);
if (afkData) {
const afkDuration = moment.duration(moment().diff(afkData.afkStartTime));
client.afkUsers.delete(message.author.id);
const embed = new EmbedBuilder()
.setColor('#00FF00')
.setTitle('AFK Modundan Çıktınız')
.setDescription(`Sebep: **${afkData.reason}**`)
.addFields(
{ name: 'AFK Başlangıç Tarihi', value: moment(afkData.afkStartTime).format('DD/MM/YYYY HH:mm:ss'), inline: true },
{ name: 'AFK Süresi', value: formatDuration(afkDuration), inline: true }
)
.setThumbnail(message.author.displayAvatarURL({ dynamic: true, format: 'png', size: 1024 }))
.setTimestamp();
await message.reply({ embeds: [embed] });
}
// Etiketlenen kullanıcılar için AFK kontrolü
message.mentions.users.forEach(user => {
const afkData = client.afkUsers.get(user.id);
if (afkData) {
const afkDuration = moment.duration(moment().diff(afkData.afkStartTime));
const embed = new EmbedBuilder()
.setColor('#FFA500')
.setTitle('Kullanıcı AFK')
.setDescription(`${user.tag} şu sebepten AFK: **${afkData.reason}**`)
.addFields(
{ name: 'AFK Başlangıç Tarihi', value: moment(afkData.afkStartTime).format('DD/MM/YYYY HH:mm:ss'), inline: true },
{ name: 'AFK Süresi', value: formatDuration(afkDuration), inline: true }
)
.setThumbnail(user.displayAvatarURL({ dynamic: true, format: 'png', size: 1024 }))
.setTimestamp();
message.reply({ embeds: [embed] });
}
});
// Selamlaşma sistemi
const greetings = {
morning: ["Günaydın!", "Günaydın, nasılsın?", "Merhaba, günaydın!", "Günaydın, güzel bir gün olsun!"],
hello: ["Merhaba!", "Selam!", "Esenlikler!", "Merhaba, nasılsın?", "Selam, umarım iyisindir.", "Merhabalar!", "Hey! Naber?"],
erdogan: ["Silivri, olmaz."],
night: ["İyi Geceler!", "Umarım iyi uyku çekersiniz!", "Geceniz güzel geçsin!", "Tatlı rüyalar!"]
};
const lower = message.content.toLowerCase();
const hour = moment().tz("Europe/Istanbul").hour();
let reply = null;
if (hour >= 6 && hour < 15 && ['günaydın', 'güno', 'gunaydın', 'gunaydin', 'guno'].some(w => lower.includes(w)))
reply = greetings.morning[Math.floor(Math.random() * greetings.morning.length)];
else if (['merhaba', 'helu', 'hello', 'helo', 'hellü', 'hellu', 'selam', 'helü'].some(w => lower.includes(w)))
reply = greetings.hello[Math.floor(Math.random() * greetings.hello.length)];
else if (['erdogan', 'erdoğan', 'tayyip', 'tayip', 'tayyoş', 'tayyos', 'tayoş'].some(w => lower.includes(w)))
reply = greetings.erdogan[Math.floor(Math.random() * greetings.erdogan.length)];
else if ((hour >= 21 || hour < 5) && ['iyi geceler', 'gece', 'geco', 'iyi geco', 'geceler'].some(w => lower.includes(w)))
reply = greetings.night[Math.floor(Math.random() * greetings.night.length)];
if (reply) await message.channel.send(reply);
});
// Dinamik AFK süresi formatlama fonksiyonu
function formatDuration(duration) {
let afkDurationString = '';
if (duration.hours() > 0) afkDurationString += `${duration.hours()} saat `;
if (duration.minutes() > 0) afkDurationString += `${duration.minutes()} dakika `;
if (duration.seconds() > 0) afkDurationString += `${duration.seconds()} saniye`;
return afkDurationString.trim() || '0 saniye';
}
client.login(config.token);