Code Your Own Discord Bot - Advanced Command Handler (2021)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys welcome back to my desk or dance tutorial at this tutorial I won't be showing you guys how to create an advanced discord command handler last episode I showed you how to create the basic command handler and most of you can probably use that method if you're not creating very big BOTS but if you're starting to create you know tens maybe hundreds of commands make sure to use this method it's gonna be a lots a lot easier to basically handle all of those comments so let's go ahead and get started if you're completely new here make sure to check out last video where I showed you how to code this code right here we're actually gonna be using this code in this tutorial so if you want to check that out me make sure to check that out and also make sure to check out the first video where I teach you how to basically set everything up all the developer tools as well as all of the discord that fill up our tools as well so make sure to check those two videos out so let's actually get started so the first thing I do is actually create a require because we have to require something called FS for us to be able to get into other you know JavaScript files so we're gonna do is gonna do you Const next make sure it's not caps so Const FS it's going to require FS just like that it's pretty simple well next thing I want to do is create kind of like a collection a disco collection or we can have all over command stored so we're gonna do client that commands equals new discord collection let's open parentheses like that and just like that's we have a discord collection next thing we do is kind of make sure that's all of the files that we're going to read our JavaScript files so we're not reading some other files so to do that we're gonna do is you const command files it's going to u equal FS dot read adder sync make sure it's sync just like that and then we're gonna do is open up in parentheses we're going to kind of go back a folder and kind of start to tell a code where it can find all of our commands so we're actually going to create a command folder here in a directory so if you come here you can actually create a folder you can also do that in finder if you don't you know have Visual Studio code installed so go back into wherever you started coding your disk or BOTS and you set everything up and create a folder it commenced you can name it whatever you wants and that is where we're gonna store all of the comments by using this method so we're gonna do dots / commands and this is basically tailing this code to go back one actually not go back one it's just going to tell it to go into the commands folder right here and then after this we're gonna filter and we're gonna filter everything to make sure that it is a JavaScript file and it's not some other kind of file so we do file we're gonna do a arrow function we're gonna do you file that ends with and we're gonna open this up and we are you should close this you guys can see going to do a parenthesis or single quotation mark sorry and we're gonna do dots Jess and let's close that just like that and then what we do now it's kind of kind of do a for loop so it's going to loop through all the files to make sure it's getting the correct file to execute our commands I'm gonna do for Const file off command files and we're gonna open this up and what I do is do Const command equals require and in here we're do is do the back quotation mark which is above the tab next year one below the escape just like this so this shift version of this if I can get it it's my shift broken wait it's actually not working no way alright guys let me go ahead and check my keyboard to make sure this is actually working alright so I checked it out there was actually some kind of problem it was like forcing me onto the shift which you don't necessarily have to shift so just like this this is the back quotation marks and in here when dudes do dot slash commands and then just the same thing as up here and then we're gonna do is we're going to go next to it put a money sign and then open brackets and then type in the file I know this is very weird if you're new to coding and then we're gonna end it off just like that and then one more thing I'm going to do clients that's command dot sets and we're gonna set command dot name and we're gonna also pass in command and that's actually all we have to kind of code in the you know the main dodgy yes this is kind of our bulk of our coding we're gonna do some things down here but before we do things down here let's actually create our command JavaScript files so let's open up command folder and create a new file we're gonna basically do with the basic ping command screen I do ping dodge it yes in here there's a couple things we got to do the first thing that to do is do module dot exports it's gonna equal open that with brackets and in here we can pretty much start adding information about our command so the first thing is probably the name so the name we're gonna just do ping let's do a comma and then the next thing we do is the description description and then we can add a description to our BOTS so everything to you this is a ping command not incorrectly today and then one final thing is we're gonna do a comma and we're gonna do you execute running that passing message and arcs and this is basically where you want to start to type all of the code that is going to get executed when the message author or whatever user is using the command all that code make sure to start typing it here so last video we had all our code down here just basically copy that code and you can start adding your code here so last time we did was a message to channel that sent and we're just gonna send bag pong just like that and then the final thing we actually have to do is go back into the main dodge ES file go down here into the if statements that we did a last episode and we're going to just simply do client that commands not yet and we're gonna get the pink amid and then we're gonna execute execute and we're gonna pass a message I'm going to pass in args just like that and that's actually all you have to basically code for this to work we're gonna go over some things that we can do with it but if we actually open up our terminal or a command prompt and we do know to space dots and let's see we've got an error up here the error is we didn't have an N right here so command just like that it's actually clear this no space knots there you go our bot is online let's go ahead and go back into our discord server type in ping and we are gonna get pong so what's basically happening is we are kind of creating separate files for all of recommence instead of typing all the functionality of the execute functions in here it's much easier to just code everything on a separate file so let's say we were to do something like kick somebody or send an embed send anything you basically want to code data right here inside this execute function that we created right here so if you want to send something else in pong so we actually have another thing right here which is last time we did YouTube so this sense YouTube they get a link to our YouTube channel what we can do is simply go ahead go into our comments create another you know J's file let's just name a YouTube - a yes and kind of do this stack same thing that we did on a pink file so let's actually copy this paste it here change the name to YouTube change the description to sense the youtube link or something like that and here what we can do is type our youtube link which is HTTP let me just type it real quick www.youtube.com / code lion come back here and then we can do exactly the same thing which is up here and this is YouTube dot X acute execute message and arcs and just like that we created the other command so let's open up the terminal let's go ahead and close out of that clear it and run it again and if we go back into our discourse server we can do ping and work pong and we can do YouTube and it will send the youtube link which is actually the exact same thing that we did last tutorial as you can see here but using this advanced method and I'm gonna be using this event events method pretty much for all my videos because I think it's an easier way to read the code because you can just go back and forth between the files instead of just going through a huge main - yes file and if you aren't creating a bot that has a lot of command so use this if you're not don't necessarily put this thing away this method here and use the basic one you can still use this and you should probably still use this but if you are creating kind of like a maybe a prototype or maybe a very very small bot to make sure you use the other one I should say make sure but you could use the other basic method but this is probably the best method method that all of the commercial BOTS use pretty much all the big BOTS use this method because it's very easy just to sorts all the files source all the commands and have them kind of organized here on your directory with that being said it's actually for this video I'm gonna need you guys's help for the upcoming video so I kind of want to know what you guys want me to code next so make sure to leave it in the comment section below I do have a note add with a lots of comments from other videos but it would be nice if you guys let me know in the comment section below and I'll write those down with that being said I'll see you guys later on my next video peace
Info
Channel: CodeLyon
Views: 254,141
Rating: undefined out of 5
Keywords: discord commands tutorial, discord commands bot, discord bot commands tutorial, discord app tutorial, discord bot development, discord command handler, discord js, discord server, basic discord bot, code discord bot, code your own discord bot, coding tutorial, dyno commands, how to add bot commands discord, how to add commands on discord, install discord bot, make your own discord bot, make your own discord bot 2020, make your own discord bot commands, personal discord bot
Id: AUOb9_aAk7U
Channel Id: undefined
Length: 10min 11sec (611 seconds)
Published: Mon Jun 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.