Complete Music System | Discord.JS V13 Series | #14

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to leeks code in today's video we're going to be creating a complete multi-guild music system using the package disto what you see now on your screen is a little preview of what that finished product will be looking like after we're done with the video [Music] now [Music] [Music] [Music] all right so to start off we're gonna be needing to install a couple of packages into our um both folder so i'm gonna leave all of these packages or all of these commands down in the description so you can just copy and paste so first of all we're gonna be npm updating so we're gonna turn off the bots and we're gonna type npm update to update every single package that we have installed with our boat after that is done we're gonna go ahead and download this tube i'm going to leave them in order they don't need to be in order down the description but i'm going to read them all in the way and because we're going to be using the spotify plugin with this this tube we can also download it so npm i this you spotify and then we're going to be needing to download ffmpeg static now if this doesn't work for you i'm going to leave a link down in the description showing you how to install fmpeg inside of your system so but for me it works so i'm gonna download it this way and then we're gonna be needing to download this package so we're gonna paste it and download it and then we're gonna need to download yt search so this you can will be able to search for youtube links or songs and then last but not least the y tdl core so npmi why today core and so far so good we have downloaded downloaded every single package that we need all right so now i'm using my own handler uh click the card up to the right of your screen to uh get the link for a event handler and the command handler that i'm using but if you have your own you can just alter it to fit with your handlers there is no problem so first off what we're going to be doing is actually create the the client or create the client property so we're gonna go to our main or what doesn't matter what kind of p index.js so we're gonna go and add a couple more lines and here we can type cones and between these brackets type this tube with a capital d and get a capital t and then we're gonna require that this new package so this tube and because we're using a plug-in called spotify we're gonna also require it so let's open accounts leave the dev lock empty and then require at this tube spotify and we close out of the line and here we gonna require the spotify plugin all right so now we're gonna go down a couple more lines and here we're gonna type client dot this tube equal new this tube all right and here we're going to give it that line so we're going to pass index lines and we're going to create an object and inside of the object we're going to have our options now i'm gonna show you what we can have so i will leave this uh the link for their documentation down in the description if you want to check it out so if you go over here to let's see this tube option over here we're gonna get all of the options that we would normally or need so first of all i'm gonna make it uh emit new songs only because it's defaulted to false i'm gonna make it through so i'm gonna copy that name and make it true all right and we're gonna make it a leave on finish and leave on empty so leave on empty is defaulted by true so we don't need to add that but leave on finish is defaulted to false now if you want your boat to be constantly connected connected to the whole channel you can leave this at as false but i don't want it to be like that so i'm gonna set it to true and now here we're gonna go down and we're gonna shake here so here we have the emit add song when creating cue it's defaulted to true but i don't think it's necessary so i'm gonna change it to be false i'm gonna tell you why when we create our events later on and here we can add the plugins so because we have a spotify plugin that we want to be added we're going to create an array and here we're going to type new spotify plugin and that should be it all right so now that we have done with creating a new client property which is this tube we're gonna model exported for our events later on when we create them so model exports and here we're gonna export that client all right so so far we're good we created our uh this tube client and now we'll move on to the next step all right so we're gonna go to our commands folder and to the systems we're gonna create a new file and we're gonna call it music.js so this is the file that is going to contain all of our music commands in one if you want to split it up to be multiple files you can do that but i don't recommend do that to do that because it's it's going to be pretty simple so here we're going to require a couple of or extract a couple of parameters from the discord.js package so we're going to have cons open a new or open an object and here we're going to require discord.js and all we need from rediscover.js is the command interaction and the message embed all right so so far so good now we're going to go down multiple lines and we're going to model both exports we're going to set the command name to be a music so music and here you can set your own description i'm gonna set it to be complete music system and then here we gonna set the permission i would recommend set the permission for now to be administrator while we are gonna be testing it so nobody uh randomly uses the commands while you are actively developing it so administrator and now here we gonna create our options inside of an array alright so the first option is gonna be or the first sub command of the music command is gonna be play so name [Music] is gonna be see play description play as song and then the type of it is going to be sub commands so sub underscore command and here we're going to create our options for the sub commands so we're going to create an array and an object inside of the narray i just noticed while recording uh we wrote option in here it should be options with an s now back to the video so the name is obviously gonna be a query all right the description is gonna be a provide a name or a url for the zone and the type of it is going to be string [Music] and it's going to be required set to true so it's pretty simple this is our first option or sub command and now we're going to create the other one so it's going to be for a volume so name here we're going to have it volume and then let me move my mic a little bit all right now description is gonna be uh alter the volume for example you can change all of this text however you want the top of it is gonna be also sub command because it's going to have its own options and here for the options we're going to create an array and then objects so this the name is going to be percent because that's how we're going to be changing out the volume with percent and description here we're going to tell them basically 10 means then 10 percent all right now the type of it's going to be number so number it's going to be required set to true now we have created our volume and play command so now we're going to go down to the options like you saw in the beginning of the video we had many options so we're gonna create the name options uh or actually you can make it settings because why not and the description is gonna be select an option uh or select a choice whatever you want it to be the type is going to be also sub command and then options and the name of it is going to be let's put the space here i'm kind of ocd choices let's actually change it to be options all right uh so um description it's going to be select let's say select an option all right and then it's going to be type string it's going to be required set to true and also here we would require we should be it should be required now back to the video again and then we're going to have we're gonna go down one more line like this and we're gonna create our choices so choices let's see let's put a comma at the end of this all right so the first choice is gonna be let's create a template all right so name and value put a comma and let's copy paste this a couple of times so let's do it like this all right so the first option is going to be q to display the queue and it's going to have the same value the second choice is going to be skip and it's going to have the same value and then pause it's going to have the same value resume the same value then we have stop and it's gonna have the value of stop now we can remove this extra one all right so once that is done we're basically done with the command layout this is how it's going to be and if we created any errors in here we'll go back to it and fix it all right so we're going to put a comma at the end of this array the options array and we're going to async execute interaction and client because we're going to be using the client properties in here all right now here we're going to grab our parameters so direction let's see here [Music] interaction is it's called command interaction story and for the client it's gonna be client and we need to add client in here so client all right it's pretty simple we can remove this extra line because why not uh so the first thing that we're gonna be doing here we're gonna extract a couple of objects from the interaction so we're gonna have const options member guild channel equal interaction so we're getting all of these options from the interaction so we don't have to type interaction to channel interaction with guide all the time all right and now we're gonna get the voice channel of the interaction member so here we're going to type const voice channel equals to member.voice.channel it should be member not member alright so that is done here we're going to shake so if the member is not in a voice channel we're going to send a message saying that you must be in a voice channel to use the music commands pretty logical so if exclamation mark voice channel then begin the return interaction dot reply uh the content is gonna be it's not gonna be with an embed because it's uh not necessary here we're gonna type you must be in a voice channel to be able to use the music commands you can customize this message and you can put it also to be a thermal set to true so only that interaction member sees it all right so now we're gonna shake so if the boat is inside a channel all right so let's say the boat is already playing music inside of a channel and somebody requested the boat to join their channel so we're gonna tell them i'm already playing in this channel so if dialed and here we gonna access the client where the client is so me dot voice um and we're gonna grab the channel id obviously and voice channel dot id isn't equal to guild dot me dot voice dot channel id so here we're getting the voice channel id of the member so if you're checking if i'm in if the bot is already in the channel right so if i'm already in a channel and the member is also in the channel but it's it's different than mine and here we gonna return we can copy this line over here and place it here and here we can exchange the content and we're gonna say um i um let's change this to backticks and here we're gonna say i am already playing uh playing music in and here we're gonna add this brackets and the hash and we're gonna provide the guide dot me dot channel sorry.voice channel id and that should link it all right so pretty simple now we have we are done with our shakes all right so now we're gonna type try try we're gonna open a block and uh at the end of the try we're gonna uh basically catch it if an error happens we're gonna catch it so we're gonna type catch e as an error and here we're gonna create an embed so called embed or error embed new message sorry embed alright we're going to set the color to be red we're going to set the description to be with backticks here we're going to add an emoji resembling it's an error or an alert all right and then here we're going to pass in the actual error all right so pretty simple and we can actually hit return interaction go to reply and builds and we're gonna here pass in the error embed just like this and we should be good to go so let's open this up a little bit just like this and now we're gonna create um what we call a switch like you can create if statements like this but for this case creating a switch function is but much better we're going to type switch sorry switch and now here we're gonna uh shake so because we have three sub commands here we're gonna shake or we're going to get to know what sub command that the user shows so here we're going to type options dot get sub command all right and we're going to open this code block let's remove some of this so here we're gonna check so case play so if the member shows play as their sub commands all right then we're gonna actually play so what we're gonna do sorry for the notification what we're going to do is we're going to type client dot this tube just like this dot play voice channel all right like this guys it's very case sensitive now here we're going to provide the voice channel which is the members in and then here we're going to provide the song like you see here so uh voice channel or stage channel and then song so how we get the song we get the song by uh receiving the value of this question so what we're gonna type over here is options dot get sorry string and here we're gonna get the string from the query all right and then we're gonna create an object so we're gonna add a comma in here and we're gonna create an object and we're gonna specify the text channel to be channel which we already extracted from the interaction over here and then member is going to be the actual interaction member and this should be it so let's add a space here remove the space and add this closing line statement and now we're gonna go under it and here we're gonna type return interaction dot reply with the content here we're gonna type uh let's add an emoji and let's add uh let's see what we have so let's add this emoji for example request receive and whenever a song plays we're gonna once we created our events uh we're gonna be able to send the embeds all right so but we're returning because we need to return something if we created an interaction so now we're done with our play command we're gonna we have our volume command all right so now we're gonna go down here and we're gonna type case uh volume all right we can execute whatever is inside of this code block so here we're gonna type const volume equals to options dot get a number we're gonna get it from the volume would we name it no we're gonna get it from the percent all right percent and then we're gonna go down one more line and we're gonna shake so if volume is bigger than 100 or if volume is less see less than one then we're gonna return interaction dot reply content and we can return basically uh that you have to specify a number between one and ten you have to specify a number with win one and a hundred sorry not ten all right so once that is done we gonna go down let's close this line we're gonna go down and type client dot this tube dot set volume and here we're going to provide the bush channel and we're also going to provide the volume pretty simple and then here we're going to return interaction go to reply content begin a return let's add an emoji this one for example [Music] vol um has been set to actually let's make this backtick so we can provide the volume set to uh and here we can add this styling and here we're gonna type volume and then add the percent sign pretty simple so far close out of this line and we're good to go so so far we are done with our play commands and we're we're done with our volume command it's it's pretty simple and not now with the settings so um we're going to create another switch statement inside of the switch statement so we're going to go down here and type let's actually go down here we're going to type case settings so if the member shows settings the subcommand settings we're going to execute this code so if uh they show the settings we're going to define the queue so const u equals a weight client of this tube dot get q and here we're gonna provide the voice channel and that's it then we're gonna go down one more line and we're going to check if exclamation mark queue so if the queue doesn't exist we're going to return interaction dot reply a content is going to be let's add this emoji there is no queue for example you can change this message to be whatever you want and now here we're going to create our switch statement so like you see here we have a lot of options so and we need to know which option the member shows so we can act on it so we're going to create another switch statement so switch and here we're going to type options dot get string and we're going to get it from let's see here the options see yes options so get string from options and then we gonna create our code block and now case skip for example because we have the the option let's actually do the queue first or why not do the skip first so let's do the the skip first all right so let's not open this so we can make our code clear here we're gonna await q dot skip and we're gonna provide the bush channel just like this and then here we're gonna return return interaction dot reply content is gonna be let's add an emoji so where is the escape emoji list let's take this emoji and here we gonna type song has been skipped and this is it so we're done with our skip command so now case stop so if the member should stop do we gonna await q dot stop and here we're gonna provide the voice channel and then we're gonna return let's actually copy this written message all right we can change the the emoji to be this not pause mention the the pole the stop so where is it i think it's this one all right um music has been stopped and now we're done with our stop command so let's do our case so case let's see case pause and here we're going to type await q dot pause provide the voice channel and we're gonna paste the reply and here we're gonna change the emoji and where is the pose this is the pose um queue or song or whatever song has been paused all right so now for the resume what we can do is copy this all right paste it under it and change the case to be resume and here we can type resume instead of pause and here we can say resumed and let's change the emoji to be this resume sound pretty simple so far or actually because this doesn't look good let's add let's see let's add this emotion all right so now all we need to do is create the queue so we're gonna go down one more line and here we're gonna type case and um here we can now return into reaction dot reply embeds and inside of them but we're gonna create a message embed or inside of that array let's go down one more line set the color of it to be for example purple and then here we're gonna set the description let's move it up a little bit let's just like this all right and inside of the description we get a map so let's open this real quick open this backticks add the dollar sign and this brackets we're gonna type q okay i don't know how to say this word sorry songs dot map and here we get a map actually let's go down one more line like like this and here we're gonna map song and id we're gonna create an error function and here we can uh add the backticks and let's uh with each zoom we're gonna create a new line so we're gonna type slash or this slash n then here we're gonna uh provide make it bold and provide the id plus one because you know how arrays work the actual um the actual first uh something in the array is going to be zero so that's why we're adding the the one so um how are we gonna put another dot and here we're gonna provide the song dot name and then we're gonna create a slash or whatever we're gonna style it and inside of the styling we're gonna type song dot formatted duration this is already defined by the actual package you don't have to define anything and let's make it more nice by doing this and this should be enough this should be it for our q commands let's add this close or let's close this line and now we're going to go down here and we're going to type return and let's clean up a little bit the spaces and this should be it our code is basically 99 um what's called 99 rows all right so now let's head over to our events so before we do that we're going to go to their documentation and let's actually go to the mp npm page so this tube npm let's go over here and let's go to their example both i'm gonna leave the link for it down in the description and let's go to their index.js so like you see here on line 52 they have all of the events um and here so what you can do is you can copy this all right copy from 51 to 75 let's go to our events folder create a new folder and call it this tube all right and here we're going to type this tube advanced dot js what we're going to do here because we exported let's see structures because we exported the this tube or the client we can require it in the events so it's pretty simple what we're going to do is type const client equals to require slash dot slash structures slash main [Music] and then we can require the message embed from that discord package so require discord.js and now here we can paste the code that we copied from over here all right so first of all what you need to do is remove all of this client emotes because we don't have them defined as so let's remove all of them and i think this should be it all right so what you can do to make them an embed it's pretty simple so like you see here but it's getting the text channel from the queue and like the other ones and it's sending the stakes but we do we don't want it in the normal format we want it in the embedded format so it's very simple what you can do is ctrl x this line for example let's create a space and let's remove this spaces and here we're gonna type we can create an object and name it embeds or specified embeds and here we gonna inside of it create new message embed so we can create a new embed we can go down one more line here we can set it to be green all right go down one more line set the description and paste whatever we copied inside of here and let's add an emoji so this is how you make your embed basically so let's make it like this so it's a little bit more organized so you can do this with all of these like i said you can crop this all right and type embeds new message and bid set the color of it to be green for example set the description and paste whatever you extracted just like this and you can add the emoji so um you can do that for all of them and by the way you can remove this search result you can remove it and you can remove the search cancel because we don't want to use them so you can do this to all of the events over here and that you can remove this one there's no result but i'm gonna keep it so i'm gonna transfer them or making embeds out of them and i'm gonna come back to you alright so now that i've created my embeds and the changed from content to embeds i think we are pretty finished so we have everything set up and we should be good to go so let's clear our console and type node space dot let's see if we have any errors we don't and i could see here updated youtube dl to whatever so now let's try slash music play and here we're gonna tap no copy right music for example and request received let me unmute myself and like you see it's pretty loud uh you can alter the volume from here or you can type slash um music volume 10 or whatever and should be good to go i want to do all of the commands now because i've already showed you in the beginning of the video but this is it so i hope you guys have enjoyed this video and i hope to see you on the next one
Info
Channel: Lyxcode
Views: 3,348
Rating: undefined out of 5
Keywords: discord music, discord.js music bot, discord.js music bot slash commands, discord, discord music bot, how to create discord music bot, distube, music bot, music bot commands, lyxcode, how to create discord.js bot, discord.js v13 music bot, create discord.js music commands, music commands, how to create a music bot using discord.js, groovy, mee6, discord.js, discord.js v13
Id: qP1LIkGoNX4
Channel Id: undefined
Length: 32min 12sec (1932 seconds)
Published: Sun Nov 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.