-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
116 lines (94 loc) · 3.6 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { Client, GatewayIntentBits, Collection, Routes, EmbedBuilder, ChannelType } from 'discord.js';
import { REST } from '@discordjs/rest';
import { Player } from 'discord-player';
import fs from 'fs';
import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
import dotenv from 'dotenv';
import Play from './commands/play.js';
import Skip from './commands/skip.js';
import Pause from './commands/pause.js';
import Resume from './commands/resume.js';
import Stop from './commands/stop.js';
import Lyrics from './commands/lyrics.js';
import Loop from './commands/loop.js';
dotenv.config();
const config = JSON.parse(fs.readFileSync('./config.json', 'utf-8'));
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
client.commands = new Collection();
const player = new Player(client, {
ytdlOptions: {
quality: "highestaudio",
highWaterMark: 1 << 25
},
leaveOnEmpty: false,
leaveOnEnd: false,
leaveOnStop: false
});
player.extractors.loadDefault((ext) => ext !== 'YouTubeExtractor');
const commands = [];
client.commands.set(Play.data.name, Play.execute);
client.commands.set(Skip.data.name, Skip.execute);
client.commands.set(Pause.data.name, Pause.execute);
client.commands.set(Resume.data.name, Resume.execute);
client.commands.set(Stop.data.name, Stop.execute);
client.commands.set(Lyrics.data.name, Lyrics.execute);
client.commands.set(Loop.data.name, Loop.execute);
commands.push(Play.data.toJSON());
commands.push(Skip.data.toJSON());
commands.push(Pause.data.toJSON());
commands.push(Resume.data.toJSON());
commands.push(Stop.data.toJSON());
commands.push(Lyrics.data.toJSON());
commands.push(Loop.data.toJSON());
const eventsPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
import(pathToFileURL(filePath).href).then(event => {
if (event.default.once) {
client.once(event.default.name, (...args) => event.default.execute(...args));
} else {
client.on(event.default.name, (...args) => event.default.execute(...args));
}
}).catch(error => console.error(`Error loading event file ${file}:`, error));
}
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand() || !interaction.guildId) return;
try {
const func = client.commands.get(interaction.commandName);
await func(interaction, player);
} catch (error) {
const embed = new EmbedBuilder().setTitle('Bir şeyler ters gitti!!')
.setDescription('Çalma sırasında bir hata oluştu')
.setTimestamp(new Date());
return interaction.followUp({ embeds: [embed] });
}
});
const rest = new REST({ version: '10' }).setToken(config.token);
(async () => {
try {
console.log('Uygulama (/) komutlarını yenilemeye başladım.');
await rest.put(
Routes.applicationCommands(config.client_id),
{ body: commands },
);
console.log('Başarıyla uygulama (/) komutlarını yeniledim.');
} catch (error) {
console.error(error);
}
})();
client.login(config.token);
process.on('unhandledRejection', (reason) => {
console.error('Yakalanmamış vaad hatası:', reason);
});
process.on('uncaughtException', (error) => {
console.error('Yakalanmamış istisna:', error.message);
});