-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
distubeClient.js
109 lines (94 loc) · 3.75 KB
/
distubeClient.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
const Distube = require('distube');
const { YouTubePlugin } = require('@distube/youtube');
const { SoundCloudPlugin } = require('@distube/soundcloud');
const { SpotifyPlugin } = require('@distube/spotify');
const { DeezerPlugin } = require('@distube/deezer');
const { EmbedBuilder } = require('discord.js');
const discordClient = require('./discordClient');
const ytdl = require('@distube/ytdl-core');
const fs = require('fs');
// Lese die Cookies aus einer JSON-Datei (z. B. cookies.json)
const cookies = JSON.parse(fs.readFileSync('cookies.json'));
// Erstelle den Agent mit den Cookies
const agent = ytdl.createAgent(cookies);
const distube = new Distube.default(discordClient, {
plugins: [
new YouTubePlugin(), // Add YouTube plugin
new SoundCloudPlugin(),
new SpotifyPlugin(),
new DeezerPlugin(),
],
});
// Erhöhe die Anzahl der maximalen Listener
distube.setMaxListeners(20); // Oder eine andere Zahl
const status = (queue) => {
const filterText = Array.isArray(queue.filters) ? queue.filters.join(', ') : 'Off';
return `Volume: \`${queue.volume}%\` | Loop: \`${queue.repeatMode ? queue.repeatMode === 2 ? 'All Queue' : 'This Song' : 'Off'}\` | Autoplay: \`${queue.autoplay ? 'On' : 'Off'}\` | Filter: \`${filterText}\``;
};
// Verwende die ytdlOptions beim Abrufen von Songs
distube
.on('playSong', (queue, song) => {
const embed = new EmbedBuilder()
.setColor('#7200FF')
.setAuthor({ name: 'Started Playing', iconURL: 'https://raw.githubusercontent.com/ballaual/DiCoBo/master/assets/music.gif' })
.setThumbnail(song.thumbnail)
.setDescription(`[${song.name}](${song.url})`)
.addFields(
{ name: '**Views:**', value: song.views.toString(), inline: true },
{ name: '**Likes:**', value: song.likes.toString(), inline: true },
{ name: '**Duration:**', value: song.formattedDuration.toString(), inline: true },
{ name: '**Status**', value: status(queue).toString() }
)
.setFooter({ text: `Requested by ${song.user.username}`, iconURL: song.user.avatarURL() })
.setTimestamp();
queue.textChannel.send({ embeds: [embed] });
})
.on('addSong', (queue, song) => {
const embed = new EmbedBuilder()
.setTitle(':ballot_box_with_check: | Added song to queue')
.setDescription(`\`${song.name}\` - \`${song.formattedDuration}\` - Requested by ${song.user}`)
.setColor('#7200FF')
.setTimestamp();
queue.textChannel.send({ embeds: [embed] });
})
.on('addList', (queue, playlist) => {
const embed = new EmbedBuilder()
.setTitle(':ballot_box_with_check: | Add list')
.setDescription(`Added \`${playlist.name}\` playlist (${playlist.songs.length} songs) to queue\n${status(queue)}`)
.setColor('#7200FF')
.setTimestamp();
queue.textChannel.send({ embeds: [embed] });
})
.on('error', (textChannel, e) => {
console.error(e);
textChannel.send(`An error encountered: ${e}`);
})
.on('finishSong', queue => {
const embed = new EmbedBuilder()
.setDescription(`:white_check_mark: | Finished playing \`${queue.songs[0].name}\``);
queue.textChannel.send({ embeds: [embed] });
})
.on('disconnect', queue => {
const embed = new EmbedBuilder()
.setDescription(':x: | Disconnected from voice channel');
queue.textChannel.send({ embeds: [embed] });
})
.on('empty', queue => {
const embed = new EmbedBuilder()
.setDescription(':x: | Channel is empty. Leaving the channel!');
queue.textChannel.send({ embeds: [embed] });
})
.on('initQueue', (queue) => {
queue.autoplay = false;
queue.volume = 50;
});
// Verwende ytdlOptions nur beim Abrufen von Songs
distube.on('playSong', async (queue, song) => {
try {
const songInfo = await ytdl.getInfo(song.url, { agent });
// Hier kannst du die songInfo verwenden, um weitere Informationen zu erhalten
} catch (error) {
console.error(error);
}
});
module.exports = distube;