├── config.json ├── commands ├── info │ ├── ping.js │ └── help.js └── music │ ├── shuffle.js │ ├── skip.js │ ├── stop.js │ ├── volume.js │ ├── resume.js │ ├── skip-all.js │ ├── pause.js │ ├── skip-to.js │ ├── remove.js │ ├── loop.js │ ├── now-playing.js │ ├── queue.js │ └── play.js ├── README.md ├── package.json ├── handlers └── command.js └── index.js /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "prefix" : "YOUR PREFIX HERE" 3 | 4 | 5 | } 6 | -------------------------------------------------------------------------------- /commands/info/ping.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: "ping", 3 | category: "info", 4 | description: "Returns latency and API ping", 5 | run: async (client, message, args) => { 6 | message.channel.send(`Pong - ${client.ws.ping}ms`) 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # discord.js-musicbot 2 | ## A LATEST DISCORD.JS MUSIC BOT 3 | A POWERFUL DISCORD MUSIC BOT BY PARAS 4 | 5 | 6 | .env 7 | ```TOKEN = XXXXXXXX``` 8 | NO YT API REQUIRED 9 | 10 | SUPPORT SERVER 11 | https://discord.gg/akYvjDK 12 | 13 | 14 | 15 | MAKE SURE TO CHECK YOU HAVE PUT 16 | ```client.queue = new Map()``` 17 | in your Main file 18 | -------------------------------------------------------------------------------- /commands/info/help.js: -------------------------------------------------------------------------------- 1 | const discord = require("discord.js"); 2 | 3 | module.exports = { 4 | name: "help", 5 | run: async (client, message, args) => { 6 | const embed = new discord.MessageEmbed() 7 | 8 | .setTitle(`${client.user.username} HELP MENU`) 9 | 10 | .setThumbnail( 11 | message.author.displayAvatarURL({ dynamic: true, size: 1024 }) 12 | ) 13 | 14 | .setDescription( 15 | ` 16 | 17 | **MUSIC COMMANDS** 18 | \`play[p],search,pause,resume,stop,skip,skipall,skipto,nowplaying[np],queue,loop,remove,volume\` 19 | 20 | 21 | **INFO COMMANDS** 22 | \`ping,help\` 23 | 24 | __**ABOUT BOT**__ 25 | A POWERFUL MUSIC BOT MADE 24/7 MUSIC PLAYERS 26 | 13+ COMMANDS 27 | ` 28 | ) 29 | .setFooter(message.guild); 30 | message.channel.send(embed); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MUSIC-BOT", 3 | "version": "0.0.1", 4 | "description": "DISCORD.JS LETEST MUSIC BOT", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js" 8 | }, 9 | "dependencies": { 10 | "express": "^4.17.1", 11 | "discord.js": "^12.5.0", 12 | "discord-canvas": "^1.3.2", 13 | "moment": "^2.29.1", 14 | "dotenv": "^8.2.0", 15 | "ascii-table": "^0.0.9", 16 | "fs": "^0.0.2", 17 | "ytdl-core": "^4.1.3", 18 | "simple-youtube-api": "^5.2.1", 19 | "@discordjs/opus": "^0.3.2", 20 | "opusscript": "^0.0.7", 21 | "ytdl-core-discord": "^1.2.4", 22 | "yt-search": "^2.5.1" 23 | }, 24 | "engines": { 25 | "node": "12.x" 26 | }, 27 | "repository": { 28 | "url": "" 29 | }, 30 | "license": "MIT", 31 | "keywords": [ 32 | "PARAS", 33 | "MUSIC", 34 | "PARAS-GAMING" 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /commands/music/shuffle.js: -------------------------------------------------------------------------------- 1 | const Discord = require("discord.js"); 2 | 3 | module.exports = { 4 | name: "shuffle", 5 | aliases: ["sf", "shufflequeue"], 6 | run: async (client, message, args) => { 7 | const Channel = message.member.voice.channel; 8 | 9 | if (!Channel) return message.channel.send("JOIN TO A VOICE CHANNEL"); 10 | 11 | const Queue = await client.queue.get(message.guild.id); 12 | 13 | if (!Queue) 14 | return message.channel.send( 15 | "Nothing Is Playing In This Server" 16 | ); 17 | 18 | const Current = await Queue.Songs.shift(); 19 | 20 | Queue.Songs = Queue.Songs.sort(() => Math.random() - 0.5); 21 | await Queue.Songs.unshift(Current); 22 | 23 | const Embed = new Discord.MessageEmbed() 24 | .setColor("RANDOM") 25 | .setTitle("Success") 26 | .setDescription("🎶 Queue Has Been Shuffled") 27 | .setTimestamp(); 28 | 29 | return message.channel.send(Embed).catch(() => message.channel.send("🎶 Queue Has Been Shuffled")); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /commands/music/skip.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: 'skip', 3 | run: async (client, message, args) => { 4 | const { channel } = message.member.voice; 5 | if (!channel) return message.channel.send("JOIN VOICE CHANNEL BEFORE USING THIS COMMAND!"); 6 | if (message.guild.me.voice.channel !== message.member.voice.channel) { 7 | return message.channel.send("JOIN MY VOICE CHANNEL IF YOU WANT USE ME!"); 8 | } 9 | const serverQueue = client.queue.get(message.guild.id); 10 | if (!serverQueue) return message.channel.send("❌ **Nothing playing in this server"); 11 | try { 12 | serverQueue.connection.dispatcher.end(); 13 | return message.channel.send({ 14 | embed:{ 15 | color: "BLUE", 16 | description:"⏩ Skipped" 17 | }}) 18 | } catch { 19 | serverQueue.connection.dispatcher.end(); 20 | await channel.leave(); 21 | return message.channel.send("TRY AGAIN TO SKIP") 22 | } 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /commands/music/stop.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: 'stop', 3 | 4 | run: async (client, message, args) => { 5 | const { channel } = message.member.voice; 6 | if (!channel){ message.channel.send("JOIN VOICE CHANNEL BEFORE USING THIS COMMANDS!")} 7 | if (message.guild.me.voice.channel !== message.member.voice.channel) { 8 | return message.channel.send("BE IN SAME VOICE CHANNEL"); 9 | } 10 | const serverQueue = client.queue.get(message.guild.id); 11 | try { 12 | if (serverQueue) { 13 | serverQueue.songs = []; 14 | serverQueue.connection.dispatcher.end() 15 | message.guild.me.voice.channel.leave(); 16 | } else { 17 | channel.leave(); 18 | } 19 | return message.channel.send({embed: { 20 | description:'↪ Disconnected'}}) 21 | } catch { 22 | serverQueue.connection.dispatcher.end(); 23 | await channel.leave(); 24 | return message.channel.send("TRY AGAIN"); 25 | } 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /commands/music/volume.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | name: 'volume', 4 | aliases: ["vol"], 5 | run: async (client, message, args) => { 6 | const { channel } = message.member.voice; 7 | if (!channel) return message.channel.send("JOIN VOICE CHANNEL!"); 8 | if (message.guild.me.voice.channel !== message.member.voice.channel) { 9 | return message.channel.send("You Have To Be In The Same Channel With The Bot!"); 10 | } 11 | const serverQueue = client.queue.get(message.guild.id); 12 | if (!serverQueue){message.channel.send("There is nothing playing!")} 13 | if (!args[0]) return message.channel.send(`The current volume is: **${serverQueue.volume}**`); 14 | try { 15 | serverQueue.volume = args[0]; 16 | serverQueue.connection.dispatcher.setVolumeLogarithmic(args[0] / 5); 17 | return message.channel.send(`I have set the volume to **${args[0]}**`); 18 | } catch { 19 | return message.channel.send("TRY AGAIN!"); 20 | } 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /commands/music/resume.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: 'resume', 3 | 4 | run: async (client, message, args) => { 5 | const { channel } = message.member.voice; 6 | if (!channel) { message.channel.send("MUST JOIN VC BEFORE USING THIS COMMAND!") 7 | } 8 | const serverQueue = client.queue.get(message.guild.id); 9 | if (message.guild.me.voice.channel !== message.member.voice.channel) { 10 | return message.channel.send("JOIN MY VOICE CHANNEL IF YOU WANT USE ME!"); 11 | } 12 | try { 13 | if (serverQueue && !serverQueue.playing) { 14 | serverQueue.playing = true; 15 | serverQueue.connection.dispatcher.resume(); 16 | return message.channel.send({embed:{ 17 | color: "BLUE", description:'▶ **Resumed**'}}); 18 | } 19 | return message.channel.send('**There is nothing to resume**.'); 20 | } catch { 21 | serverQueue.connection.dispatcher.end(); 22 | return message.channel.send("**TRY AGAIN**") 23 | } 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /commands/music/skip-all.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: 'skipall', 3 | aliases: ['skip-all'], 4 | run: async (client, message, args) => { 5 | const { channel } = message.member.voice; 6 | if (!channel) return message.channel.send('I\'m sorry but you need to be in a voice channel to skip music!'); 7 | if (message.guild.me.voice.channel !== message.member.voice.channel) { 8 | return message.channel.send("**You Have To Be In The Same Channel With The Bot!**"); 9 | } 10 | const serverQueue = client.queue.get(message.guild.id); 11 | if (!serverQueue) return message.channel.send("Nothing playing in this server"); 12 | if (!serverQueue.songs) return message.channel.send("There are No Songs In The Queue!"); 13 | try { 14 | serverQueue.songs = []; 15 | serverQueue.connection.dispatcher.end(); 16 | return message.channel.send("✅Skipped All Songs**"); 17 | } catch { 18 | serverQueue.connection.dispatcher.end(); 19 | await channel.leave(); 20 | return message.channel.send("TRY AGAIN"); 21 | } 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /commands/music/pause.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: "pause", 3 | run: async (client, message, args) => { 4 | const serverQueue = client.queue.get(message.guild.id); 5 | const { channel } = message.member.voice; 6 | try { 7 | if (!channel) 8 | return message.channel.send( 9 | "I'm sorry but you need to be in a voice channel to pause music!" 10 | ); 11 | if (message.guild.me.voice.channel !== message.member.voice.channel) { 12 | return message.channel.send( 13 | "YOU HAVE TO BE IN SAME VOICE CHANNEL IF YOU WANT PAUSE MUSIC" 14 | ); 15 | } 16 | if (serverQueue && serverQueue.playing) { 17 | serverQueue.playing = false; 18 | serverQueue.connection.dispatcher.pause(true); 19 | return message.channel.send({ 20 | embed: { 21 | color: "BLUE", 22 | description: "**⏸ PAUSED**" 23 | } 24 | }); 25 | } 26 | return message.channel.send("**There is Nothing Playing!**"); 27 | } catch { 28 | serverQueue.connection.dispatcher.end(); 29 | await channel.leave(); 30 | } 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /commands/music/skip-to.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: "skipto", 3 | 4 | run: async (client, message, args) => { 5 | if (!args[0]) 6 | return message.channel.send("**Please Enter A Song Number!**"); 7 | 8 | const { channel } = message.member.voice; 9 | if (!channel) return message.channel.send("JOIN VOICE CHANNEL!"); 10 | const serverQueue = client.queue.get(message.guild.id); 11 | if (!serverQueue) { 12 | message.channel.send("Nothing playing in this server"); 13 | } 14 | 15 | if (message.guild.me.voice.channel !== message.member.voice.channel) { 16 | return message.channel.send( 17 | "You Have To Be In The Same Channel With The Bot!" 18 | ); 19 | } 20 | 21 | if (args[0] < 1 && args[0] >= serverQueue.songs.length) { 22 | return message.channel.send("**Please Enter A Valid Song Number!**"); 23 | } 24 | try { 25 | serverQueue.songs.splice(0, args[0] - 2); 26 | serverQueue.connection.dispatcher.end(); 27 | return; 28 | } catch { 29 | serverQueue.connection.dispatcher.end(); 30 | await channel.leave(); 31 | return message.channel.send("PLEASE TRY AGAIN"); 32 | } 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /commands/music/remove.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: "remove", 3 | aliases: ["rs"], 4 | run: async (client, message, args) => { 5 | if (!args[0]) return message.channel.send("**Please Enter A Song Number!**") 6 | 7 | const { channel } = message.member.voice; 8 | if (!channel) return message.channel.send('I\'m sorry but you need to be in a voice channel to remove a particular song number!'); 9 | if (message.guild.me.voice.channel !== message.member.voice.channel) { 10 | return message.channel.send("**You Have To Be In The Same Channel With The Bot!**"); 11 | }; 12 | const serverQueue = client.queue.get(message.guild.id); 13 | if (!serverQueue) return message.channel.send("Nothing playing in this server"); 14 | try { 15 | if (args[0] < 1 && args[0] >= serverQueue.songs.length) { 16 | return message.channel.send("Please Enter A Valid Song Number!"); 17 | } 18 | serverQueue.songs.splice(args[0] - 1, 1); 19 | return message.channel.send(`Removed song number ${args[0]} from queue`); 20 | } catch { 21 | serverQueue.connection.dispatcher.end(); 22 | return message.channel.send("TRY AGAIN!") 23 | } 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /handlers/command.js: -------------------------------------------------------------------------------- 1 | const { readdirSync } = require("fs"); 2 | 3 | const ascii = require("ascii-table"); 4 | 5 | // Create a new Ascii table 6 | let table = new ascii("Commands"); 7 | table.setHeading("Command", "Load status"); 8 | 9 | module.exports = client => { 10 | // Read every commands subfolder 11 | readdirSync("./commands/").forEach(dir => { 12 | // Filter so we only have .js command files 13 | const commands = readdirSync(`./commands/${dir}/`).filter(file => 14 | file.endsWith(".js") 15 | ); 16 | 17 | // Loop over the commands, and add all of them to a collection 18 | // If there's no name found, prevent it from returning an error, 19 | // By using a cross in the table we made. 20 | for (let file of commands) { 21 | let pull = require(`../commands/${dir}/${file}`); 22 | 23 | if (pull.name) { 24 | client.commands.set(pull.name, pull); 25 | table.addRow(file, "✅"); 26 | } else { 27 | table.addRow( 28 | file, 29 | `❌ -> missing a help.name, or help.name is not a string.` 30 | ); 31 | continue; 32 | } 33 | 34 | // If there's an aliases key, read the aliases. 35 | if (pull.aliases && Array.isArray(pull.aliases)) 36 | pull.aliases.forEach(alias => client.aliases.set(alias, pull.name)); 37 | } 38 | }); 39 | // Log the table 40 | console.log(table.toString()); 41 | }; 42 | -------------------------------------------------------------------------------- /commands/music/loop.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: "loop", 3 | aliases: ["repeat"], 4 | run: async (client, message, args) => { 5 | const { channel } = message.member.voice; 6 | if (!channel) 7 | return message.channel.send( 8 | "I'm sorry but you need to be in a voice channel to loop music!" 9 | ); 10 | const serverQueue = client.queue.get(message.guild.id); 11 | try { 12 | if (!serverQueue) 13 | return message.channel.send("There is nothing playing."); 14 | if (message.guild.me.voice.channel !== message.member.voice.channel) { 15 | return message.channel.send( 16 | "**You Have To Be In The Same Channel With The Bot!**" 17 | ); 18 | } 19 | if (!serverQueue.loop) { 20 | serverQueue.loop = true; 21 | return message.channel.send({ 22 | embed:{ 23 | color: "BLUE", 24 | description:"🔁 The queue repeat has been enabled."}}); 25 | } else { 26 | serverQueue.loop = false; 27 | return message.channel.send( 28 | {embed: { 29 | color: "BLUE", 30 | description:"🔁 The queue repeat has been disabled."}}); 31 | } 32 | } catch { 33 | serverQueue.connection.dispatcher.end(); 34 | await channel.leave(); 35 | return message.channel.send( 36 | "**Something Went Wrong, Please Try Again!**" 37 | ); 38 | } 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { Client, Collection } = require("discord.js"); 2 | const { config } = require("dotenv"); 3 | const {prefix} = require("./config.json") 4 | 5 | const client = new Client({ 6 | disableEveryone: true 7 | }) 8 | 9 | // Collections 10 | client.commands = new Collection(); 11 | client.aliases = new Collection(); 12 | client.queue = new Map(); 13 | 14 | // Run the command loader 15 | ["command"].forEach(handler => { 16 | require(`./handlers/${handler}`)(client); 17 | }); 18 | 19 | client.on("ready", () => { 20 | console.log(`Hi, ${client.user.username} is now online!`); 21 | 22 | client.user.setActivity("+help | MUSIC BOT",{type: "WATCHING"}) 23 | }) 24 | 25 | client.on("message", async message => { 26 | 27 | 28 | if (message.author.bot) return; 29 | if (!message.guild) return; 30 | if (!message.content.startsWith(prefix)) return; 31 | 32 | // If message.member is uncached, cache it. 33 | if (!message.member) message.member = await message.guild.fetchMember(message); 34 | 35 | const args = message.content.slice(prefix.length).trim().split(/ +/g); 36 | const cmd = args.shift().toLowerCase(); 37 | 38 | if (cmd.length === 0) return; 39 | 40 | // Get the command 41 | let command = client.commands.get(cmd); 42 | // If none is found, try to find it by alias 43 | if (!command) command = client.commands.get(client.aliases.get(cmd)); 44 | 45 | // If a command is finally found, run the command 46 | if (command) 47 | command.run(client, message, args); 48 | }); 49 | 50 | client.login(process.env.TOKEN); 51 | -------------------------------------------------------------------------------- /commands/music/now-playing.js: -------------------------------------------------------------------------------- 1 | const Discord = require("discord.js"); 2 | 3 | module.exports = { 4 | name: "nowplaying", 5 | aliases: ["np"], 6 | run: async (client, message, args) => { 7 | const Channel = message.member.voice.channel; 8 | 9 | if (!Channel) return message.channel.send("join voice channel after try COMMAND"); 10 | 11 | const Queue = await client.queue.get(message.guild.id); 12 | 13 | if (!Queue) 14 | return message.channel.send( 15 | "Nothing Is Playing Right Now, Add Some Songs To Queue" 16 | ); 17 | 18 | const Song = await Queue.Songs[0], 19 | Total = Song.Duration, 20 | Seconds = Song.Seconds, 21 | Time = parseInt(Queue.Bot.dispatcher.streamTime + Queue.ExtraTime); 22 | 23 | function FD(duration) { 24 | let minutes = Math.floor(duration / 60); 25 | let hours = ""; 26 | if (minutes > 59) { 27 | hours = Math.floor(minutes / 60); 28 | hours = hours >= 10 ? hours : "0" + hours; 29 | minutes = minutes - hours * 60; 30 | minutes = minutes >= 10 ? minutes : "0" + minutes; 31 | } 32 | duration = Math.floor(duration % 60); 33 | duration = duration >= 10 ? duration : "0" + duration; 34 | if (hours != "") { 35 | return hours + ":" + minutes + ":" + duration; 36 | } 37 | return minutes + ":" + duration; 38 | }; 39 | 40 | const Sec = Math.round(Time / 1000), 41 | AllTime = (Seconds * 1000).toFixed(0); 42 | const Remaining = await FD((Seconds - Sec).toFixed(0)); 43 | const Adder = await FD(Sec); 44 | const Index = Math.round((Time / AllTime) * 20); 45 | const Bar = "▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬".split(""); 46 | let ShowBar; 47 | 48 | if (Index >= 1 && Index <= 20) { 49 | Bar.splice(Index, 0, "🔵"); 50 | ShowBar = Bar.join(""); 51 | } else { 52 | ShowBar = "🔵▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬"; 53 | }; 54 | 55 | const Data = `Song - **[${Song.Title}](${Song.Link})**\nCreator - **[${ 56 | Song.Author 57 | }](${Song.AuthorLink})**\nUpload - **${ 58 | Song.Upload 59 | }**\nViews - **${Song.Views || 60 | 0}**\nDuration - **${Total}**\nRemaining - **${Remaining}**\n\n`; 61 | 62 | const Embed = new Discord.MessageEmbed() 63 | .setColor("RANDOM") 64 | .setImage(Song.Thumbnail) 65 | .setTitle("Now Playing!") 66 | .setDescription(Data + `${ShowBar}\n${Adder}/${Total}`) 67 | .setFooter(`Added By ${Song.Owner}`) 68 | .setTimestamp(); 69 | 70 | return message.channel.send(Embed); 71 | } 72 | }; 73 | -------------------------------------------------------------------------------- /commands/music/queue.js: -------------------------------------------------------------------------------- 1 | const { MessageEmbed } = require("discord.js"); 2 | 3 | module.exports = { 4 | name: "queue", 5 | aliases: ["q"], 6 | run: async (client, message, args) => { 7 | const { channel } = message.member.voice; 8 | if (!channel) 9 | return message.channel.send( 10 | "I'm sorry but you need to be in a voice channel to see queue!" 11 | ); 12 | if (message.guild.me.voice.channel !== message.member.voice.channel) { 13 | return message.channel.send( 14 | "**You Have To Be In The Same Channel With The Bot!**" 15 | ); 16 | } 17 | const serverQueue = client.queue.get(message.guild.id); 18 | if (!serverQueue) 19 | return message.channel.send("Nothing playing in this server"); 20 | try { 21 | let currentPage = 0; 22 | const embeds = generateQueueEmbed(message, serverQueue.songs); 23 | const queueEmbed = await message.channel.send( 24 | `**Current Page - ${currentPage + 1}/${embeds.length}**`, 25 | embeds[currentPage] 26 | ); 27 | await queueEmbed.react("⬅️"); 28 | await queueEmbed.react("⏹"); 29 | await queueEmbed.react("➡️"); 30 | 31 | const filter = (reaction, user) => 32 | ["⬅️", "⏹", "➡️"].includes(reaction.emoji.name) && 33 | message.author.id === user.id; 34 | const collector = queueEmbed.createReactionCollector(filter); 35 | 36 | collector.on("collect", async (reaction, user) => { 37 | try { 38 | if (reaction.emoji.name === "➡️") { 39 | if (currentPage < embeds.length - 1) { 40 | currentPage++; 41 | queueEmbed.edit( 42 | `**Current Page - ${currentPage + 1}/${embeds.length}**`, 43 | embeds[currentPage] 44 | ); 45 | } 46 | } else if (reaction.emoji.name === "⬅️") { 47 | if (currentPage !== 0) { 48 | --currentPage; 49 | queueEmbed.edit( 50 | `**Current Page - ${currentPage + 1}/${embeds.length}**`, 51 | embeds[currentPage] 52 | ); 53 | } 54 | } else { 55 | collector.stop(); 56 | reaction.message.reactions.removeAll(); 57 | } 58 | await reaction.users.remove(message.author.id); 59 | } catch { 60 | serverQueue.connection.dispatcher.end(); 61 | return message.channel.send( 62 | "**Missing Permissions - [ADD_REACTIONS, MANAGE_MESSAGES]!**" 63 | ); 64 | } 65 | }); 66 | } catch { 67 | serverQueue.connection.dispatcher.end(); 68 | return message.channel.send( 69 | "**Missing Permissions - [ADD_REACTIONS, MANAGE_MESSAGES]!**" 70 | ); 71 | } 72 | } 73 | }; 74 | 75 | function generateQueueEmbed(message, queue) { 76 | const embeds = []; 77 | let k = 10; 78 | for (let i = 0; i < queue.length; i += 10) { 79 | const current = queue.slice(i, k); 80 | let j = i; 81 | k += 10; 82 | const info = current 83 | .map(track => `${++j} :- [${track.title}](${track.url})`) 84 | .join("\n"); 85 | const embed = new MessageEmbed() 86 | .setTitle("Song Queue\n") 87 | .setThumbnail(message.guild.iconURL()) 88 | .setColor("GREEN") 89 | .setDescription( 90 | `**Current Song ⤵️ [${queue[0].title}](${queue[0].url})**\n\n${info}` 91 | ) 92 | .setFooter(`${message.guild}`) 93 | .setTimestamp(); 94 | embeds.push(embed); 95 | } 96 | return embeds; 97 | } 98 | -------------------------------------------------------------------------------- /commands/music/play.js: -------------------------------------------------------------------------------- 1 | const { Util, MessageEmbed } = require("discord.js"); 2 | const ytdl = require("ytdl-core"); 3 | const yts = require("yt-search"); 4 | 5 | module.exports = { 6 | name: "play", 7 | description: "To play songs :D", 8 | usage: "", 9 | aliases: ["p"], 10 | 11 | run: async function(client, message, args) { 12 | const channel = message.member.voice.channel; 13 | if (!channel) { 14 | message.channel.send("I am sorry but you need to be in a voice channel before using this commamd"); 15 | } 16 | 17 | if (!message.guild.me.hasPermission("CONNECT")) { 18 | message.channel.send({ 19 | embed: { 20 | color: "FF0000", 21 | description: 22 | "<:emoji_17:763367241327706118> I don't have permission to connect your vc!" 23 | } 24 | }); 25 | } 26 | if (!message.guild.me.hasPermission("SPEAK")) { 27 | message.channel.send({ 28 | embed: { 29 | color: "FF0000", 30 | description: 31 | "<:emoji_17:763367241327706118>I need speak permission for playing music!" 32 | } 33 | }); 34 | } 35 | var searchString = args.join(" "); 36 | if (!searchString) { 37 | message.channel.send("<:emoji_17:763367241327706118>provide us song' name or song's link"); 38 | } 39 | 40 | var serverQueue = message.client.queue.get(message.guild.id); 41 | 42 | var searched = await yts.search(searchString); 43 | if (searched.videos.length === 0) { 44 | message.channel.send("I can't find that song"); 45 | } 46 | var songInfo = searched.videos[0]; 47 | 48 | const song = { 49 | id: songInfo.videoId, 50 | title: Util.escapeMarkdown(songInfo.title), 51 | views: String(songInfo.views).padStart(10, " "), 52 | url: songInfo.url, 53 | ago: songInfo.ago, 54 | duration: songInfo.duration.toString(), 55 | img: songInfo.image, 56 | req: message.author 57 | }; 58 | 59 | if (serverQueue) { 60 | serverQueue.songs.push(song); 61 | let thing = new MessageEmbed() 62 | .setTitle("SONG HAS BEEN ADDED TO QUEUE") 63 | .setImage(song.img) 64 | .setColor("ORANGE") 65 | .setDescription( 66 | `**SONG NAME** 67 | [${song.title}](${song.url}) 68 | 69 | **DURACTION** 70 | ${song.duration} 71 | 72 | **REQUEST BY** 73 | [${message.author}] 74 | 75 | 76 | 77 | 78 | ` 79 | ) 80 | .setFooter(`PARAS GAMING 🇮🇳`); 81 | return message.channel.send(thing); 82 | } 83 | 84 | const queueConstruct = { 85 | textChannel: message.channel, 86 | voiceChannel: channel, 87 | connection: null, 88 | songs: [], 89 | volume: 3.5, 90 | playing: true 91 | }; 92 | message.client.queue.set(message.guild.id, queueConstruct); 93 | queueConstruct.songs.push(song); 94 | 95 | const play = async song => { 96 | const queue = message.client.queue.get(message.guild.id); 97 | if (!song) { 98 | message.client.queue.delete(message.guild.id); 99 | return; 100 | } 101 | 102 | const dispatcher = queue.connection 103 | .play(ytdl(song.url)) 104 | .on("finish", () => { 105 | queue.songs.shift(); 106 | play(queue.songs[0]); 107 | }) 108 | .on("error", error => console.error(error)); 109 | dispatcher.setVolumeLogarithmic(queue.volume / 5); 110 | let thing = new MessageEmbed() 111 | .setTitle("START PLAYING") 112 | .setDescription( 113 | ` 114 | **SONG NAME** 115 | [${song.title}](${song.url}) 116 | 117 | **DURACTION** 118 | ${song.duration} 119 | 120 | **REQUEST BY** 121 | [${message.author}] 122 | ` 123 | ) 124 | 125 | .setImage(song.img) 126 | .setColor("GREEN") 127 | .setFooter(`PARAS GAMING🇮🇳`); 128 | queue.textChannel.send(thing); 129 | }; 130 | 131 | try { 132 | const connection = await channel.join(); 133 | queueConstruct.connection = connection; 134 | channel.guild.voice.setSelfDeaf(true); 135 | play(queueConstruct.songs[0]); 136 | } catch (error) { 137 | console.error(`I could not join the voice channel: ${error}`); 138 | message.client.queue.delete(message.guild.id); 139 | //await channel.leave(); 140 | return console.log( 141 | `I could not join the voice channel: ${error}`, 142 | message.channel 143 | ); 144 | } 145 | } 146 | }; 147 | --------------------------------------------------------------------------------