-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (56 loc) · 1.99 KB
/
index.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const { Client, Intents, Collection } = require('discord.js');
const fs = require('fs');
require('dotenv').config();
const mongoose = require('mongoose');
const User = require('./models/User');
const Uptime = require('./models/Uptime');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.MESSAGE_CONTENT,
],
});
mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(() => {
console.log('Connected to MongoDB');
}).catch((error) => {
console.error('Error connecting to MongoDB:', error);
});
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log(`Bot ${client.user.tag} olarak başlatıldı!`);
});
client.on('messageCreate', (message) => {
if (!message.content.startsWith(process.env.PREFIX) || message.author.bot) return;
const args = message.content.slice(process.env.PREFIX.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName);
if (!command) return;
try {
command.execute(message, args, client);
} catch (error) {
console.error(error);
message.reply('Bir hata oluştu!');
}
});
client.on('guildMemberRemove', async (member) => {
try {
const user = await User.findOne({ discordId: member.id });
if (user) {
await Uptime.deleteMany({ userId: member.id });
await User.deleteOne({ discordId: member.id });
console.log(`Sunucudan ayrılan kullanıcı (${member.user.tag})'a ait bütün linkler, panel verileri ve kayıtlar silindi.`);
}
} catch (error) {
console.error('Sunucudan ayrılan kullanıcıya ait link, panel verisi ve kayıtları silerken bir hata oluştu:', error);
}
});
client.login(process.env.TOKEN);