//Bot Musica const Discord = require('discord.js'); const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MEMBERS", "GUILD_MESSAGES", "GUILD_VOICE_STATES"] }) client.login("token mio") require('events').EventEmitter.prototype._maxListeners = 100; const { DisTube } = require("distube") //Plugin facoltativi const { SpotifyPlugin } = require("@distube/spotify") const { SoundCloudPlugin } = require("@distube/soundcloud") const distube = new DisTube(client, { youtubeDL: false, plugins: [new SpotifyPlugin(), new SoundCloudPlugin()], leaveOnEmpty: false, leaveOnStop: true }) client.setMaxListeners(100) client.on("messageCreate", message => { if (message.content == "m!queue") { const voiceChannel = message.member.voice.channel if (!voiceChannel) { return message.channel.send("You need to be in a voice channel.") } const voiceChannelBot = message.guild.channels.cache.find(x => x.type == "GUILD_VOICE" && x.members.has(client.user.id)) if (voiceChannelBot && voiceChannel.id != voiceChannelBot.id) { return message.channel.send("Someone already hearing music from this bot.") } let queue = distube.getQueue(message) if (!queue) return message.channel.send("No queue here.") let totPage = Math.ceil(queue.songs.length / 10) let page = 1 let songsList = "" for (let i = 10 * (page - 1); i < 10 * page; i++) { if (queue.songs[i]) { songsList += `${i + 1}. **${queue.songs[i].name.length <= 100 ? queue.songs[i].name : `${queue.songs[i].name.slice(0, 100)}...`}** - ${queue.songs[i].formattedDuration}\r` } } let embed = new Discord.MessageEmbed() .addField("Queue", songsList) .setFooter({ text: `Page ${page}/${totPage}` }) let button1 = new Discord.MessageButton() .setLabel("Back") .setStyle("PRIMARY") .setCustomId("Next") let button2 = new Discord.MessageButton() .setLabel("Next2") .setStyle("PRIMARY") .setCustomId("Next") if (page == 1) button1.setDisabled() if (page == totPage) button2.setDisabled() let row = new Discord.MessageActionRow() .addComponents(button1) .addComponents(button2) message.channel.send({ embeds: [embed], components: [row] }) .then(msg => { const collector = msg.createMessageComponentCollector() collector.on("collect", i => { i.deferUpdate() if (i.user.id != message.author.id) return i.reply({ content: "Questo bottone non รจ tuo", ephemeral: true }) if (i.customId == "Back") { page-- if (page < 1) page = 1 } if (i.customId == "Next") { page++ if (page > totPage) page = totPage } let songsList = "" for (let i = 10 * (page - 1); i < 10 * page; i++) { if (queue.songs[i]) { songsList += `${i + 1}. **${queue.songs[i].name.length <= 100 ? queue.songs[i].name : `${queue.songs[i].name.slice(0, 100)}...`}** - ${queue.songs[i].formattedDuration}\r` } } let embed = new Discord.MessageEmbed() .addField("Queue", songsList) .setFooter({ text: `Page ${page}/${totPage}` }) let button1 = new Discord.MessageButton() .setLabel("Back") .setStyle("PRIMARY") .setCustomId("Back") let button2 = new Discord.MessageButton() .setLabel("Next") .setStyle("PRIMARY") .setCustomId("Next") if (page == 1) button1.setDisabled() if (page == totPage) button2.setDisabled() let row = new Discord.MessageActionRow() .addComponents(button1) .addComponents(button2) msg.edit({ embeds: [embed], components: [row] }) }) }) } if (message.content == "m!skip") { const voiceChannel = message.member.voice.channel if (!voiceChannel) { return message.channel.send("You need to be in a voice channel.") } const voiceChannelBot = message.guild.channels.cache.find(x => x.type == "GUILD_VOICE" && x.members.has(client.user.id)) if (voiceChannelBot && voiceChannel.id != voiceChannelBot.id) { return message.channel.send("Someone already hearing music from this bot.") } try { distube.skip(message) .catch(() => { return message.channel.send("There is no next song.") }) } catch { return message.channel.send("No song reproducing, or there isn't.") } message.channel.send("Song Skipped") } if (message.content == "m!previous") { const voiceChannel = message.member.voice.channel if (!voiceChannel) { return message.channel.send("You need to be in a voice channel.") } const voiceChannelBot = message.guild.channels.cache.find(x => x.type == "GUILD_VOICE" && x.members.has(client.user.id)) if (voiceChannelBot && voiceChannel.id != voiceChannelBot.id) { return message.channel.send("Someone already hearing music from this bot.") } try { distube.previous(message) .catch(() => { return message.channel.send("There isn't a previous song.") }) } catch { return message.channel.send("No song reproducing, or there isn't.") } message.channel.send("Previous Song Reproducing.") } if (message.content == "m!stop") { const voiceChannel = message.member.voice.channel if (!voiceChannel) { return message.channel.send("You need to be in a voice channel.") } const voiceChannelBot = message.guild.channels.cache.find(x => x.type == "GUILD_VOICE" && x.members.has(client.user.id)) if (voiceChannelBot && voiceChannel.id != voiceChannelBot.id) { return message.channel.send("Someone already hearing music from this bot.") } try { distube.stop(message) .catch(() => { return message.channel.send("Stopped Song.") }) } catch { return message.channel.send("No sond reproducing, or there isn't one.") } message.channel.send("Queue Stopped") } client.on("messageCreate", message => { if (message.content.startsWith("m!play")) { const voiceChannel = message.member.voice.channel if (!voiceChannel) { return message.channel.send("You need to be in a voice channel.") } const voiceChannelBot = message.guild.channels.cache.find(x => x.type == "GUILD_VOICE" && x.members.has(client.user.id)) if (voiceChannelBot && voiceChannel.id != voiceChannelBot.id) { return message.channel.send("Someone already hearing music from this bot.") } let args = message.content.split(/\s+/) let query = args.slice(1).join(" ") if (!query) { return message.channel.send("Insert a song you want.") } distube.play(voiceChannelBot || voiceChannel, query, { member: message.member, textChannel: message.channel, message: message }) } if (message.content == "m!resume") { const voiceChannel = message.member.voice.channel if (!voiceChannel) { return message.channel.send("You need to be in a voice channel.") } const voiceChannelBot = message.guild.channels.cache.find(x => x.type == "GUILD_VOICE" && x.members.has(client.user.id)) if (voiceChannelBot && voiceChannel.id != voiceChannelBot.id) { return message.channel.send("Someone already hearing music from this bot.") } try { distube.pause(message) } catch { return message.channel.send("No song playing, or paused.") } message.channel.send("Song Paused") } if (message.content == "m!resume") { const voiceChannel = message.member.voice.channel if (!voiceChannel) { return message.channel.send("You need to be in a voice channel.") } const voiceChannelBot = message.guild.channels.cache.find(x => x.type == "GUILD_VOICE" && x.members.has(client.user.id)) if (voiceChannelBot && voiceChannel.id != voiceChannelBot.id) { return message.channel.send("Someone already hearing music from this bot.") } try { distube.resume(message) } catch { return message.channel.send("No song playing, or paused.") } message.channel.send("Song Paused") } distube.on("addSong", (queue, song) => { let embed = new Discord.MessageEmbed() .setTitle("Song added") .addField("Song", song.name) queue.textChannel.send({ embeds: [embed] }) }) distube.on("playSong", (queue, song) => { let embed = new Discord.MessageEmbed() .setTitle("Playing song...") .addField("Song", song.name) .addField("Requested by", song.user.toString()) queue.textChannel.send({ embeds: [embed] }) }) distube.on("searchNoResult", (message, query) => { message.channel.send("Song Not Found.") }) })})