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

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what is gonna get welcome back to another discord dar es tutorial this is episode 2 on our how to make a discord bot in 2020 series this episode of we're going to be coding custom commands and actually I'm splitting this episode into two parts you're currently watching the first parts tomorrow morning I'm going to be releasing the second parts the reason I'm doing this is because there's actually two methods of creating custom commands and this method that I'm showing you in this video is going to be the the basic method and then next episode will be shown the advanced method so let's go and get started if you are new here make sure to go in the description and check out last video where I teach you how to set up your developer tools your coding environment as well as we set up a private little server or we can start testing our BOTS so let's go ahead and actually get started so first things first we actually have to coding our prefix if you guys know what a prefix is it's basically that symbol that any discord bot uses that basically tells the bots that they're initiating a command so for most discs or BOTS it's the exclamation mark but I think we're gonna do the minus sign for the specific BOTS so we're gonna do is we need the constant we're gonna do you prefix and it's going to equal our prefix which is going to be a minus sign or you can add anything you can do percentage submission mark whatever you want we're gonna do a minus sign next is we're gonna actually start to code our events so we're gonna do client that on and we're gonna do a message event so message just like this we're going to do message again and we're gonna do an error function and open this up before I continue I do want to say I'll actually have the code in the description below in a pastebin if you want to look through the code and if you mess up you can actually check the code see what mistakes you made which is easier than just you know kind of doing this whole entire video thing again so make sure to check the paceman below alright so the next thing what I do is actually there's two things we have to check first things we have to check is if the message started with the ping fix to continue on and if the message did not start with the prefix so just completely ignore that message and the second thing we have to check is that if the bot itself initiated the command to completely stop and don't proceed on and we do this for safety reasons as well as they could crash something's and you're coding so let's go ahead and continue so I'm gonna do if and then we're gonna open this up and we're gonna do this Commission mark and then we're gonna do message that content that starts with and when I open this up it starts it there prefix just like that which is basically telling if the content does not start with our prefix we're gonna basically do nothing and then what I'm gonna do is going to do an operational or which means there's two things that this if statement is going to check it's going to check that we start with the prefix and it's going to check that the bot itself did not sense the message to start the command and we do that by doing the or which are these two little sticks I completely forgot how to name them I actually had it behind my mind before starting this video but it's the same key as the backslash which is this one right here I'll just press shift on that and that should pop that out and then I'm gonna do message that's author that bot and we're gonna do it's just returned so it's gonna completely break off the code right here if it doesn't start with the prefix or if the author is the bots and it's just gonna return and continue on with the code all right now we're gonna do the common thing we're just gonna splice our code and then we're gonna shift it you'll see we're gonna do let's continue so I'm gonna do Const args and it's going to equal message that content that slice and we do prefix that length and then I'm gonna go here and we're gonna do dot splits and there's actually two methods of doing this last night what I did was just open this up in quotation marks and I'll leave it empty like this but I think the safer way to do this is if we do the backslash and then space plot the plus sign and then backslash just like that which is kind of the same thing so we're going to do it this method and what we're basically doing is kind of splicing our command so if you want to have thing like check and in space and then check wiki this is the splicing that we're doing right here so we can have multiple commands so let's continue on down here where do Const command and we're gonna do equals args and what I'm gonna do is win a shift and then we are going to toe to lowercase not to local lowercase we're gonna do two lowercase just like that and then finally we're gonna do is complete our commands which is actually starting to program our comments and what they're gonna do so we're gonna do if command and then we're gonna do three equal signs then we're gonna open this up with single quotations and this is gonna be kind of the name of your command that they're gonna send so the most basic thing in this tutorials are to basically start with a ping command we're gonna do Pig and then we're gonna open this up and we're gonna do is gonna do just message that's channel dot sent and we're gonna send pong back just like that and if you actually save this and then open our command prompt or we open up command prompt in here no space thoughts if you don't know how to do this make sure to check out my last video as well and that's gonna start running our BOTS as soon as it says code line is on line because that's what we coded up here check it here and if we do I think minus sign ping it's going to respond with pong so that's pretty much what you do and if you want to continue to add more comments all you got to do is continue adding more if statement so else if command equals YouTube we open this up again oh I completely did not open that correctly we're gonna do a message message that channel that's and we're gonna send youtube.com slash I think this channel is called lion just like that and if we save that open up our command prompt again do you notice based on - I'll get our bottom line back here and if we do something to actually know I keep doing this Commission it's - you - it's going to send the youtube link and I think if it's a link we have to do HTTP I think like this right to send a link yes indeed so let's actually restarts or about like that and now we do YouTube it's gonna send the youtube link just like that and you can continue adding as much commences you want all you gotta do is keep doing else if finish that off then you come down here and you do another else--if and that's pretty much it so right here this is where you name the command and inside this block right here is where you can start adding the code to your commands just it's pretty much that simple mmm you know next video tomorrow's video is actually gonna get more complicated because the reason that we have to do that video is because the method I'm showing you guys right now works pretty well perfect for small bots-bots-botswana big and big and big and its continued growing and that can hold up your code that could also have some problems later on and it's just not proficient to do if you're going to be coding so the advanced method we're basically be doing this but we're gonna be adding separate files for each command so if you want to do the ping command we're actually gonna have any JavaScript file called ping Jes and that way we can actually start coding very very advanced commands without having to make this main file a super big file super you know tons of lines of code and that's we're gonna be doing tomorrow but that actually concludes this episode here that's pretty much all you have to do to make simple commands and yeah if you guys enjoyed that make sure to check out this YouTube channel there's a lot more tutorials on this cordage is all the tutorials that I recorded about a year ago still work so if you want to go check them out make sure to check out this YouTube channel would that being said I'll see you guys later tomorrow peace
Info
Channel: CodeLyon
Views: 337,426
Rating: undefined out of 5
Keywords: code your own discord bot, how to code your own discord bot 2020, make your own discord bot, make your own discord bot 2020, make your own discord bot basics (2020), make your own discord bot commands, make your own discord bot free, make your own discord bot online, program your own discord bot, discord bot tutorial, code discord bot, how to make a discord bot, personal discord bot, discord app tutorial, discord commands, discord commands tutorial, discord js command handler
Id: nTGtiCC3iQM
Channel Id: undefined
Length: 8min 54sec (534 seconds)
Published: Fri Jun 26 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.