Advanced Command Handler | Discord.js v12 tutorials

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody welcome back to another video today and in this video we're going to be making an advanced command handler so if you haven't been watching previous videos make sure you go check them out and let's get straight into this so basically what this is gonna do is it's gonna read every single command for us instead of us having to automatically input into our index so you can simply delete all the code up in your client.on besides the user activity and the console.log this is not needed you can delete that if you don't want it there but this is just what i have so let's get into it so the first thing we want to do is we want to come into our commands and we want to make new folder called commands also then we're going to take all of our commands and put them into it now what we want to do insider commands the first folder is we want to make a file named base file or actually no we need to name it command base dot then we're also going to make an one another file inside our first commands file named in load commands dot js now for our base file what we're going to do is we're going to import our prefix so we're going to do const brackets prefix equals require dot dot slash dot dot slash means it's gonna go back out of the folder and yeah then we're just gonna config.json now what we want to do is we wanna do const validate permission equals parentheses permissions now we want to get out of the parentheses do an arrow function then a set of brackets now we want to do const valid permissions not validate need just valid then we want to equals then just a straight line now for this i'm going to be getting ins all the discord permissions it'll be in the code down below in the description for this video i'll put all the codes down there that way it's easier but i do recommend you guys watch video now that i have it all in there we can exit out there and we can do for const permission of permissions then we want to do our brackets here and then we want to do if if it is not valid permissions one put another set of insider parentheses we want to do dot includes parentheses right there and then inside parentheses we're going to do permissions just permission i mean sorry and then out of those one do our brackets and then we want to do throw new error capital e for error if i can even spell then one do parentheses or backtick then we want to do unknown permission node and then i'm just going to do my include quotation marks then i'm going to do dollar sign brackets then permission now this is basically saying that if it doesn't if there's an error it'll send it in the console or inside the chat that it is in and then i'll tell you what's wrong then you can go back and fix it now you want to go all the way out to a new line and you want to do cons all activations equals an empty array after that we want to do module.exports equals command parentheses command options now there we want to do our arrow function brackets and then go into it now we're going to do let's brackets activation since our command and name is activation then we're going to do permission permission equals an array empty array now right here we want to do equals command options now out of that we want to go down a few lines then we want to do if type of activation three equal signs then string then we want to go out there make more brackets and then in here we want to activation equals an array inside the array we want to do activation again now we got an error right here and it's because this needs to be if i misspelled now out of that we want to do console.log then we want to do our backticks registering command then i'm going to put my print our i want i'm just going to put those i forget the name of it again then dollar sign brackets then we're going to do activation and array with 0 in it now that's just going to say that all our commands are fully registering now that we want to do if type no if permission dot length then now that we want to do our brackets again then we want to if type of permissions three equal signs again undo string and now there we need to do our brackets again inside here we're just gonna do permission equals our array then permission permissions not just permission now we want to go out that and quickly right here what we want to or yeah what we want to do go down and do validate permissions with permission permission yeah permissions sorry now what we want to do is go out of it not put that there then i'm gonna do four const activation of activation then we're going to do our brackets right here inside our brackets we're going to do all activation array then we're going to do act permission and right then we're going to do activation init then out of that we're going to do an equals then we're going to put another bracket there inside of this we're going to do three dots and command options then we want to put a comma activation comma then permission permissions now after that we want to come out of it all the way then we want to do module exports dot listen then we want to do equal signs then clients right here now after the client we're going to do an arrow function then brackets again now this is going to be the thing that's going to be listening for the commands we're going to do client dot on message then after that we're going to do a comma then parentheses the message inside of it then an arrow functions and brackets now we're going to do const member content and guild equals message then we're gonna do cons arguments equals message dot content dot slice prefix dot length then now that we're gonna do dot split slash plus slash now we're going to enter again then we're going to do const cmd equals args or before that we're gonna do const args equals message or yeah sorry this right here needs to be for args so we can copy that there then for arguments what we want to do is content dot slice dot split then we're going to do slash an empty array here with a space in it then we're going to do plus slash now go back to our cm cons cmd we're going to do dot shift after rx dot 2 lower case now we're done with that one then we're gonna do const name equals arguments dots shift dot to lowercase now what we need to do is we need to do if name name dot starts with we're gonna do our parentheses then said that we're gonna do prefix inside of that and do our brackets then after that we need to do cons command equals all activations then we're going to do an empty array and then inside of it we're going to do name dot replace then we're going to be doing after the name.replace we're gonna put our parentheses in here we're into prefix comma and then our those now out of it means you if not command we'll do our bracket we need to return it so really quick new terminal just gonna quickly check out this problem so something is expected okay so right here it needs to be the um another princy right there and then we'll just wait on these for a second we're just gonna quickly finish so out of it we're into cons brackets now this is where we're going to be naming all of our stuff we're going to need permissions comma new line permission error equals you do not have permission to run this command now you can name that whatever you want that's just going to be the permission error after that we're going to do required roles equals an empty array then we're going to do min arts equals zero max args equals null and then after the max arcs we're gonna do expected args comma then our last thing will be our callback then after this we're gonna do equals command now out of that we're gonna do for const permission of permissions now that we're gonna do our brackets then we're gonna want to do if not member dot has permissions permission or input permission right here then now that we're gonna do our brackets inside our brackets we're just gonna do message dot reply then we're gonna do permission error now after that what we need to do is we're going to come out of it we're going to do four const required rolls of required roles again so we're going to do our bracket here i'm going to do const roll equals dot roles dot cash dot find then we're going to need to do a parenthesis answer then parentheses again roll dot name role then error function needs to roll dot name then after that we need to do two equal signs and required roles now we're gonna come out of that or no we're just gonna come up to here then we're going to do if not roll then we're going to do our statement so two straight lines then we're going to need to do if not member now then after that we're going to do roles.cash dot has role dot id roll.id needs to be in parentheses for that too after that we need to do brackets in the brackets we're going to do message dot reply then we're going to do brackets again now we're going to parentheses into our and do a backtick we're going to do you must have the two quotation marks dollar sign brackets required rolls out that role to use this command now this can be anything you want it it doesn't have to do the required roles but it make it a lot cleaner if you did it but you don't have to do it so now out of underneath this one we need to return it now after that we need to come down to this one we need to do if parentheses arguments dot length is less than menargs do or statement again answer do max print and max args and we're going to do x-made point two equal signs null two at signs we're gonna do arguments dot length after you do the arguments not length what you want to do is you want to do if more than men args then you can actually get out the parentheses and come down here you want to do bracket right there then inside of this bracket you want to do message don't reply then you want to do parentheses then you want to backtext then you want to make sure to use the correct form format of the command now you can come out there if it will let me there now after that you want to enter return right there now in here you want to do the callback message arguments client and args then cmd and then let me quickly figure out what these errors are and i'll be right back okay guys i'm back i just i accidentally added a extra parenthesis right there so now what you want to do is you want to come to your load commands you want to do cons path equals require path underneath that you want to do const fs equals require fs then you want to enter a few lines you want to do module.exports equals client then out the parentheses you want to arrow function then brackets then in here you want to do con space file equals then here it's just going to be command dash base no the hard part is over it was this file so we're going on the easy stuff right now then you want to do cons command files command base no sorry you want to do cons command base equals require do backticks dot slash then one do dollar sign then brackets and one do base file now you want to come over down here and you want to do cons activations then you want to do equals an empty array then you want to come down here and you want to do const raid commands equals dirt then outside of there you want to do arrow function then brackets now here you want to do const files equals fs dot read der sync then you want to do parenthesis path dot join then you want to do parentheses again under two under scores their name then commander now you can do underneath that for const file of files then you connect it to brackets inside of here you want to do cons stats equals reader sync you want to do parentheses here and then inside the parentheses you want to do path dot join then parentheses underscore name then dirt then file exit out of that and then you want to do if stat dot it is hold on i want to do if stat dot ls directory or is directory hold on let me let me quickly figure it out i completely forgot what it was okay guys it is is directory i want to do the parentheses then inside of the is directory you wanted hold on this is not read your sync it needs to be a one stat sync okay then inside the is directory you just want to leave it and you want to come out of it to brackets then inside of these brackets you want to do who read commands then after three commands you undo parentheses path dot join then you want to do after the path of joining more parentheses then dur and file then oh you need to put comma there then out of that you want to do an else if right here then after the else if you want to do parentheses then you want to do file exclamation point to equal signs base file then after base file you want to do two hat signs file an exclamation point two equal signs then after that you want to do all of the those and sorry then you want to do load commands right here inside of them dot js then you want to come out of it then do more brackets then inside of these you want to do const option equals require path dot join more parentheses underscore their name undo comma then comma file now out of those one to an if statement so if client client inside of parentheses you want to do brackets then inside the brackets you want to do command base parentheses option now you want to come down for n brackets when i enter then you want to read activation or now you want to read commands then you want to do commands the whatever you name the file inside of your commands so i named it the exact same so we're good for that so now we need to do command base dot listen for client then after that you just want to return activations now we're done with load commands hold on give me one second i have no clue what it just did here okay you want to save both of these now we're done with our commands folder now we need to go into your index up here you want to do const load commands equals require dot slash commands slash load commands then after that what you want to do is you want to do const fs equals require fs now after that what you want to do is you want to come down here then you want to load commands clients now you want to make one more file you inside of the bot you want to name it command dot js now inside of this you want to do const prefix equals require rconfig.json now after that you want to do module.exports equals client aliases and then callback then after that you want to do an arrow functions and brackets now you want to do if type of aliases three equal signs then string you want to do bracket after that you want to do aliases equals an array with aliases inside of it now you want to come down here you want to client dot on message comma inside parentheses message again i want to do an arrow function then brackets now instead of here you want to const content undo equals message now you want to do aliases alice's dot for each capital e to aliases no just alias now you want to come out of that you want to do equal signs and brackets make sure it's two parentheses two sets of parentheses now in here you want to do cons command equals backtick dollar sign prefix make sure it is backtick prefix then you want to do dollar sign alias here now you can leave that we want to do if content dot starts with and then you want to do parentheses or backtick then you want to do command dot sign brackets then command then you want to put a space and then after that you want to do an or statement so two straight lines then you want to do content then two equal signs equals command now you want to put a bracket after that i want to do console.log then you want to do backtick hick right next to the one undo running the command dollar sign command and then we're done for here so now i already did this previously but here's what you would want to do so you want to do module dot exports equals brackets then you want to do activation colons note this just activation then you want to do your command name so this one is ping comma after that one do description i don't know why it's doing this but oh well then you want to do colons then you want to do that then say what the command is so this is a pink command then you want to do comma after that you want to do expected args then you want just do the whose then comma permission error now this can be whatever you want i'm just going to say you this up here you need send messages permits to do this command you want to comment after that men args the max arcs 0 comma then call back now for this what you need to do is you need to go back to your command base you want to make sure it's this exactly so you can copy it doesn't matter but you want to make sure it's that exactly then you need to do arrow function then brackets then you want to put your command here so you're just going to do message.channel dot send punk then right here you want to put a comma don't want to do permissions then you want to put those then required roles empty array then that's it so basically required rules is if you have a specific role you want the command to be used by but i don't have that permissions i only want to send message each perm people that have the permission send messages to use it so all you have to do is do that for every single command you have make a new file and do the exact same thing now we're going to run our bot see if there's any errors so we got an error in activation before initialization so 69 line 69 in our command base so we're going to go up to line 69 for constant activation of activation so right here it needs to be not conceptivation of activations it needs to be contact vision of activations so now we can clear it and do node. now activations is not defined i'll be right back i'm going to make sure i have this all correct and i'll check in once i find out okay guys so what we need to do is here we need to put activations and to make them all activations then right here needs to be activations again and then in our all of our commands we need to just make it activations so do that there now we can save it all clear then no dots and we get a same error but different line 59 so it needs to be activations right here also clear no dot now all of our commands register as you can see right here all of our commands registered and the bot is online now we can quickly come to our test server we can do i explanation point help all right so we get an error right so we misspelled in command baseline 84. so it needs prefix not what i mistyped now we can do expansion point help again see what our new error is to lower case so this is line 85 so this needs to be capital l not lowercase clear no dot then expect help again to lower case line 87 now all right for some reason i accidentally keep making these all not capitalized so quickly run through it looks like they are all capitalized for the rest on so clear no dot now we're going to do help again get a new error acquired roles command base 111 required rules here it needs to be let me quickly check to make sure i have this correct um so i'll be right back you guys all you have to do is just remove the s on this one then it should be good now we need to run explain help again make sure you use correct format so there was something that happened um so that it's right now saying make sure to use quick format um and we did run it correctly so okay guys it's just this needs to be arguments not arguments this might be the last one i'm not entirely sure so still need to use correct formats let me try the ping command okay so yeah we did mess up somewhere so let me go back and check make sure i got it all correct and i will be right back with you guys okay guys so it does not need to be monarchs it needs to be max arcs right here so that's what i messed up on so now we can do i help express point help still get the same thing um pretty sure that's all that needs to be done okay guys i'm back so it needs to be arguments right there because of all this so that should be the last thing for this file if there is any errors so you do explain help now we get a new error this one is in okay so it's just we need to make sure we name it correctly so arguments and then um quickly go through make sure i close it all the arguments are or arguments looks like it so we can save it right no dot help there we go now we do ping uh hi embed they all work now for the embeds what you need to do it's the exact same way that i showed you guys last time but make sure you go check that video and all that so that's the end of this video and i hope you guys enjoyed so have a good day and i'll see you guys later bye
Info
Channel: CodeViper
Views: 28
Rating: undefined out of 5
Keywords:
Id: Y63u7abF9K8
Channel Id: undefined
Length: 37min 51sec (2271 seconds)
Published: Sat Jun 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.