-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (44 loc) · 1.66 KB
/
Copy pathindex.js
File metadata and controls
57 lines (44 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import "dotenv/config";
import fs from "fs";
import { Client, GatewayIntentBits, Collection } from "discord.js";
import { initDatabase } from "./services/database.js";
import { startStatsService } from "./services/statsChannel.js";
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
client.commands = new Collection();
const PREFIX = "!";
// Komutları yükle
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = await import(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once("ready", async () => {
console.log(`${client.user.tag} olarak giriş yapıldı.`);
console.log(`${client.commands.size} komut yüklendi.`);
// Veritabanını başlat
await initDatabase();
// Stats servisini (arka plan görevini) başlat
startStatsService(client);
console.log("Stats servisi ve Veritabanı başlatıldı.");
});
client.on("messageCreate", async (message) => {
if (message.author.bot) return;
if (!message.content.startsWith(PREFIX)) return;
const args = message.content.slice(PREFIX.length).trim().split(/\s+/);
const commandName = args.shift()?.toLowerCase();
if (!client.commands.has(commandName)) return;
const command = client.commands.get(commandName);
try {
await command.execute(message, args, client);
} catch (error) {
console.error(error);
message.reply("Komutu çalıştırırken bir hata oluştu!");
}
});
client.login(process.env.DISCORD_TOKEN);