Files
commands
events
utils
.gitignore
bot.js
config.json
package.json
README.md
Code
33 1,323
bot.js
const { Client, GatewayIntentBits, Collection, ActivityType, EmbedBuilder } = require('discord.js');
const fs = require('fs');
const path = require('path');
require('dotenv').config();
const Database = require('./utils/database');
const config = require('./config.json');
const MinecraftServer = require('./utils/minecraft');
const cron = require('node-cron');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildModeration
]
});
client.commands = new Collection();
client.cooldowns = new Collection();
client.userMessages = new Collection();
client.db = new Database();
client.config = config;
const commandFolders = fs.readdirSync('./commands');
for (const folder of commandFolders) {
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${folder}/${file}`);
client.commands.set(command.name, command);
}
}
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
}
if (config.minecraftStatus.enabled) {
setInterval(async () => {
try {
const status = await MinecraftServer.getStatus();
if (status.online) {
client.user.setPresence({
activities: [{
name: `${status.players.online}/${status.players.max} Oyuncu Oynuyor`,
type: ActivityType.Playing
}],
status: 'online'
});
} else {
client.user.setPresence({
activities: [{
name: 'Sunucu Çevrimdışı',
type: ActivityType.Playing
}],
status: 'dnd'
});
}
} catch (error) {
console.error('Minecraft sunucu durumu güncellenemedi:', error);
}
}, config.minecraftStatus.updateInterval);
}
cron.schedule('0 0 * * 0', async () => {
try {
const suggestions = client.db.getWeeklySuggestions();
if (suggestions.length === 0) return;
suggestions.sort((a, b) => b.votes - a.votes);
const winner = suggestions[0];
const founder = await client.users.fetch(process.env.FOUNDER_USER_ID);
const suggester = await client.users.fetch(winner.userId);
const embed = new EmbedBuilder()
.setTitle('🏆 Haftanın Kazanan Önerisi')
.setDescription(winner.suggestion)
.addFields(
{ name: 'Öneren', value: `<@${winner.userId}>`, inline: true },
{ name: 'Oy Sayısı', value: `${winner.votes} oy`, inline: true }
)
.setColor(config.embedColor)
.setTimestamp();
await founder.send({ embeds: [embed] });
client.db.clearWeeklySuggestions();
} catch (error) {
console.error('Haftalık öneri kazananı gönderilemedi:', error);
}
}, {
timezone: "Europe/Istanbul"
});
client.login(process.env.DISCORD_TOKEN);