forked from Ly3ssia/music-bot-v14
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
329 lines (316 loc) · 13.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
const { Client, Collection, GatewayIntentBits, Partials } = require("discord.js")
const Discord = require("discord.js")
const client = new Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.GuildVoiceStates,
Discord.GatewayIntentBits.MessageContent
]
})
const config = require("./src/config.js");
const { readdirSync } = require("fs")
const moment = require("moment");
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v10');
const { DisTube } = require('distube')
const { SpotifyPlugin } = require('@distube/spotify')
const { SoundCloudPlugin } = require('@distube/soundcloud')
const { YtDlpPlugin } = require('@distube/yt-dlp')
const { Player } = require("discord-player")
const db = require("croxydb")
const languagefile = require("./src/language.json")
const player = new Player(client);
client.player = player;
client.distube = new DisTube(client, {
leaveOnStop: false,
leaveOnFinish: true,
emitNewSongOnly: true,
emitAddSongWhenCreatingQueue: false,
emitAddListWhenCreatingQueue: false,
plugins: [
new SpotifyPlugin({
emitEventsAfterFetching: true
}),
new SoundCloudPlugin(),
new YtDlpPlugin()
]
})
let token = config.token
client.commands = new Collection()
const rest = new REST({ version: '10' }).setToken(token);
const commands = [];
readdirSync('./src/commands').forEach(async file => {
const command = require(`./src/commands/${file}`);
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
})
client.distube.on("finish", queue => {
client.guilds.cache.filter(guild => {
const data = db.fetch(`music_${guild.id}`)
if (!data) return;
const mesaj = data.mesaj
const channels = data.kanal
const channel = guild.channels.cache.get(channels)
const messagef = channel.messages.fetch(mesaj).then(async messagef => {
messagef.edit({content: "🎵 | Music ended.", embeds: [], components: []}).catch(err => {})
})
})
})
client.on("ready", async () => {
client.guilds.cache.filter(guild => {
const data = db.fetch(`music_${guild.id}`)
if (!data) return;
db.delete(`music_${guild.id}`)
})
})
client.on("ready", async () => {
try {
await rest.put(
Routes.applicationCommands(client.user.id),
{ body: commands },
);
} catch (error) {
console.error(error);
}
console.log(`Bot logged in as ${client.user.tag}!`);
})
readdirSync('./src/events').forEach(async file => {
const event = require(`./src/events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
})
client.on("interactionCreate", interaction => {
if (interaction.customId === "fast") {
const queue = client.distube.getQueue(interaction);
if (!queue) return interaction.reply(`There is no song on the list yet.`)
let data = db.fetch(`music_${interaction.guild.id}`)
if (!data) return interaction.reply({content: "I'm sorry.Error **404**", ephemeral: true})
queue.filters.add("nightcore")
interaction.reply({content: "Speed online!", ephemeral: true})
}
if (interaction.customId === "slowmode") {
const queue = client.distube.getQueue(interaction);
if (!queue) return interaction.reply(`There is no song on the list yet.`)
let data = db.fetch(`music_${interaction.guild.id}`)
if (!data) return interaction.reply({content: "I'm sorry.Error **404**", ephemeral: true})
queue.filters.add("vaporwave")
interaction.reply({content: "Slowmode online!", ephemeral: true})
}
if (interaction.customId === "bassboost") {
const queue = client.distube.getQueue(interaction);
if (!queue) return interaction.reply(`There is no song on the list yet.`)
let data = db.fetch(`music_${interaction.guild.id}`)
if (!data) return interaction.reply({content: "I'm sorry.Error **404**", ephemeral: true})
queue.filters.add("bassboost")
interaction.reply({content: "Bassboost online!", ephemeral: true})
}
if (interaction.customId === "soru") {
const queue = client.distube.getQueue(interaction);
if (!queue) return interaction.reply(`There is no song on the list yet.`)
let data = db.fetch(`music_${interaction.guild.id}`)
if (!data) return interaction.reply({content: "I'm sorry.Error **404**", ephemeral: true})
const part = Math.floor((queue.currentTime / queue.songs[0].duration) * 20);
const embed = new Discord.EmbedBuilder()
.setColor('Purple')
.setDescription(`**[${queue.songs[0].name}](${queue.songs[0].url})**`)
.setImage(`${queue.songs[0].thumbnail}`)
.addFields({ name: 'Music Author:', value: `[${queue.songs[0].uploader.name}](${queue.songs[0].uploader.url})`, inline: true })
.addFields({ name: 'Member:', value: `${queue.songs[0].user}`, inline: true })
.addFields({ name: 'Voice:', value: `${queue.volume}%`, inline: true })
.addFields({ name: 'Views:', value: `${queue.songs[0].views}`, inline: true })
.addFields({ name: 'Like:', value: `${queue.songs[0].likes}`, inline: true })
.addFields({ name: 'Filtre:', value: `${queue.filters.names.join(', ') || "Normal"}`, inline: true })
.addFields({ name: `Video Time: **[${queue.formattedCurrentTime} / ${queue.songs[0].formattedDuration}]**`, value: ` ${'<:circle:1033057941647016056>'.repeat(part) + '🎵' + '<:asd:1033046466438107158>'.repeat(20 - part)}`, inline: false })
return interaction.reply({embeds: [embed], ephemeral: true}).catch(err => {})
}
if (interaction.customId === "dur") {
const queue = client.distube.getQueue(interaction);
if (!queue) return interaction.reply(`There is no song on the list yet.`)
let data = db.fetch(`music_${interaction.guild.id}`)
if (!data) return interaction.reply({content: "I'm sorry.Error **404**", ephemeral: true})
let usır = data.user
let string = data.string
if (interaction.user.id !== usır) return interaction.reply({content: "Only the person who wrote the command can use this button.", ephemeral: true})
const baslik = data.başlık
const author = data.yükleyen
const sure = data.süre
const izlenme = data.görüntülenme
const thumb = data.thumb
const url = data.video
const embed = new Discord.EmbedBuilder()
.addFields({name: "Title", value: `${baslik}`, inline: true})
.addFields({name: "Author", value: `${author}`, inline: true})
.addFields({name: "Time", value: `${sure}`, inline: true})
.addFields({name: "Views", value: `${izlenme}`, inline: true})
.addFields({name: "Thumbnail", value: "[Click]("+thumb+")", inline: true})
.addFields({name: "Video", value: "[Click]("+url+")", inline: true})
.setColor("Aqua")
.setImage(`${thumb}`)
const row = new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setEmoji("🎵")
.setStyle(Discord.ButtonStyle.Danger)
.setCustomId("devam")
)
client.distube.pause(interaction)
return interaction.update({embeds: [embed], components: [row]})
}
if (interaction.customId === "skip") {
const queue = client.distube.getQueue(interaction);
if (!queue) return interaction.reply(`There is no song on the list yet.`)
let data = db.fetch(`music_${interaction.guild.id}`)
if (!data) return interaction.reply({content: "I'm sorry.Error **404**", ephemeral: true})
if (queue.songs.length === 1) return interaction.reply("No song found in the queue!")
let usır = data.user
let string = data.string
if (interaction.user.id !== usır) return interaction.reply({content: "Only the person who wrote the command can use this button.", ephemeral: true})
const baslik = data.başlık
const author = data.yükleyen
const sure = data.süre
const izlenme = data.görüntülenme
const thumb = data.thumb
const url = data.video
const embed = new Discord.EmbedBuilder()
.addFields({name: "Title", value: `${baslik}`, inline: true})
.addFields({name: "Author", value: `${author}`, inline: true})
.addFields({name: "Time", value: `${sure}`, inline: true})
.addFields({name: "Views", value: `${izlenme}`, inline: true})
.addFields({name: "Thumbnail", value: "[Click]("+thumb+")", inline: true})
.addFields({name: "Video", value: "[Click]("+url+")", inline: true})
.setColor("Aqua")
.setImage(`${thumb}`)
client.distube.skip(interaction)
return interaction.update({embeds: [embed]})
}
if (interaction.customId === "loop") {
const queue = client.distube.getQueue(interaction);
if (!queue) return interaction.reply(`There is no song on the list yet.`)
let data = db.fetch(`music_${interaction.guild.id}`)
if (!data) return interaction.reply({content: "I'm sorry.Error **404**", ephemeral: true})
let usır = data.user
let string = data.string
if (interaction.user.id !== usır) return interaction.reply({content: "Only the person who wrote the command can use this button.", ephemeral: true})
const baslik = data.başlık
const author = data.yükleyen
const sure = data.süre
const izlenme = data.görüntülenme
const thumb = data.thumb
const url = data.video
const embed = new Discord.EmbedBuilder()
.addFields({name: "Title", value: `${baslik}`, inline: true})
.addFields({name: "Author", value: `${author}`, inline: true})
.addFields({name: "Time", value: `${sure}`, inline: true})
.addFields({name: "Views", value: `${izlenme}`, inline: true})
.addFields({name: "Thumbnail", value: "[Click]("+thumb+")", inline: true})
.addFields({name: "Video", value: "[Click]("+url+")", inline: true})
.setColor("Aqua")
.setImage(`${thumb || "https://cdn.discordapp.com/attachments/997487955860009038/1009062859889705062/Baslksz-1.png"}`)
client.distube.setRepeatMode(interaction, 1);
return interaction.update({embeds: [embed]})
}
if (interaction.customId === "devam") {
const queue = client.distube.getQueue(interaction);
if (!queue) return interaction.reply(`There is no song on the list yet.`)
let data = db.fetch(`music_${interaction.guild.id}`)
if (!data) return interaction.reply({content: "I'm sorry.Error **404**", ephemeral: true})
let usır = data.user
let string = data.string
if (interaction.user.id !== usır) return interaction.reply({content: "Only the person who wrote the command can use this button.", ephemeral: true})
const baslik = data.başlık
const author = data.yükleyen
const sure = data.süre
const izlenme = data.görüntülenme
const thumb = data.thumb
const url = data.video
const embed = new Discord.EmbedBuilder()
.addFields({name: "Title", value: `${baslik}`, inline: true})
.addFields({name: "Author", value: `${author}`, inline: true})
.addFields({name: "Time", value: `${sure}`, inline: true})
.addFields({name: "Views", value: `${izlenme}`, inline: true})
.addFields({name: "Thumbnail", value: "[Click]("+thumb+")", inline: true})
.addFields({name: "Video", value: "[Click]("+url+")", inline: true})
.setColor("Aqua")
.setImage(`${thumb}`)
const row = new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setEmoji("🎵")
.setStyle(Discord.ButtonStyle.Secondary)
.setCustomId("dur"),
new Discord.ButtonBuilder()
.setEmoji("🔊")
.setStyle(Discord.ButtonStyle.Secondary)
.setCustomId("volume"),
new Discord.ButtonBuilder()
.setEmoji("⏩")
.setStyle(Discord.ButtonStyle.Secondary)
.setCustomId("skip"),
new Discord.ButtonBuilder()
.setEmoji("🌀")
.setStyle(Discord.ButtonStyle.Secondary)
.setCustomId("loop"),
new Discord.ButtonBuilder()
.setEmoji("❓")
.setStyle(Discord.ButtonStyle.Secondary)
.setCustomId("soru")
)
const row2 = new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setEmoji("🥁")
.setStyle(Discord.ButtonStyle.Secondary)
.setCustomId("bassboost"),
new Discord.ButtonBuilder()
.setEmoji("<:slowmode:740952943460614185>")
.setStyle(Discord.ButtonStyle.Secondary)
.setCustomId("slowmode"),
new Discord.ButtonBuilder()
.setEmoji("💨")
.setStyle(Discord.ButtonStyle.Secondary)
.setCustomId("fast"),
new Discord.ButtonBuilder()
.setLabel("Support Server")
.setStyle(Discord.ButtonStyle.Link)
.setURL("https://discord.gg/altyapilar")
)
client.distube.resume(interaction)
interaction.update({embeds: [embed], components: [row, row2]})
}
})
const modal = new Discord.ModalBuilder()
.setCustomId('form')
.setTitle('Raven - Music Bot!')
const a1 = new Discord.TextInputBuilder()
.setCustomId('setvolume')
.setLabel('Volume')
.setStyle(Discord.TextInputStyle.Paragraph)
.setMinLength(1)
.setPlaceholder('1 - 100')
.setRequired(true)
const row = new Discord.ActionRowBuilder().addComponents(a1);
modal.addComponents(row);
client.on('interactionCreate', async (interaction) => {
if(interaction.customId === "volume"){
await interaction.showModal(modal);
}
})
client.on('interactionCreate', async interaction => {
if (interaction.type !== Discord.InteractionType.ModalSubmit) return;
if (interaction.customId === 'form') {
const string = interaction.fields.getTextInputValue('setvolume')
const volume = parseInt(string)
const queue = client.distube.getQueue(interaction);
if (!queue) return interaction.reply(`There is no song on the list yet.`)
if (isNaN(volume)) return interaction.reply("Give me number!")
if (volume < 1) return interaction.reply("The number must not be less than 1.")
if (volume > 100) return interaction.reply("The number should not be greater than 100.")
client.distube.setVolume(interaction, volume);
interaction.reply("Successfully set the volume of the music to **"+volume+"**")
}
})
client.login(token)