-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpapaz.js
80 lines (71 loc) · 3.05 KB
/
papaz.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
74
75
76
77
78
79
80
const { Client, Collection, GatewayIntentBits, Partials, InteractionType } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent
],
partials: [Partials.Message, Partials.Channel, Partials.GuildMember, Partials.Reaction, Partials.User]
});
const fs = require("fs");
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v10');
const allah = require("./config.json");
// Komutları yükleme
client.commands = new Collection();
client.slashcommands = new Collection();
const slashcommands = [];
fs.readdirSync('./src/Commands/').forEach(category => {
const commandFiles = fs.readdirSync(`./src/Commands/${category}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./src/Commands/${category}/${file}`);
client.commands.set(command.conf.name, command);
command.conf.aliases.forEach(alias => client.commands.set(alias, command));
}
});
fs.readdirSync('./src/Slashcommands/').forEach(category => {
const slashFiles = fs.readdirSync(`./src/Slashcommands/${category}`).filter(file => file.endsWith('.js'));
for (const file of slashFiles) {
const command = require(`./src/Slashcommands/${category}/${file}`);
client.slashcommands.set(command.data.name, command);
slashcommands.push(command.data.toJSON());
}
});
// Slash komutlarını Discord API'ye yükleme
const rest = new REST({ version: '10' }).setToken(allah.token);
(async () => {
try {
await rest.put(
Routes.applicationGuildCommands(allah.BotClientID, allah.GuildID),
{ body: slashcommands }
);
console.log('[Bot] Slash komutları yüklendi.');
} catch (error) {
console.error('Slash komutları yüklenirken hata oluştu:', error);
}
})();
// Slash komutlarının çalıştırılması
client.on('interactionCreate', async (interaction) => {
if (interaction.type !== InteractionType.ApplicationCommand || interaction.user.bot) return;
const command = client.slashcommands.get(interaction.commandName);
if (!command) return interaction.reply({ content: "Bu komut kullanılamıyor.", ephemeral: true });
try {
await command.execute(interaction, client);
} catch (error) {
console.error('Komut çalıştırılırken hata oluştu:', error);
await interaction.reply({ content: "Komut çalıştırılırken bir hata meydana geldi!", ephemeral: true });
}
});
// Botu başlatma
client.login(allah.token)
.then(() => console.log("Bot başarıyla bağlandı!"))
.catch(() => console.log("Bot bağlanamadı!"));
process.on("uncaughtException", (err) => {
console.error("Beklenmedik bir hata oluştu:", err.stack);
});
process.on("unhandledRejection", (err) => {
console.error("Promise hatası:", err);
});