Creating Commands | Discord.js v12 tutorials

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome back to another video today so this time we're gonna be making our commands we're just gonna do a simple command and that's gonna be it so the first thing you wanna do is you wanna come to is go watch the first video it there will be a notification top right to watch the first video if you haven't but first thing you want to do is you want to put go to your config.json and do quotation marks and you want to do prefix this is your prefix obvious up at the end of your token you need to put comment then right here just put what you want your prefix to be so i'm just going to put an explanation point and then save it and we're done with this file now what we need to do is we need to do client.on need to do parentheses then quotation mark you need to message here then leave it to message then arrow function then there um and then you need to put a comma right after message now once you do that you need to make a function so the first thing we need to do is do if i message then you do content dot starts with now for here you need to do brackets then you need to do config dot prefix then out of graphic goods you need to do or which is just two straight lines and then you do message dot author dot bot now basically what this is the need to do return after it and then semicolon it's not necessary but it you just prefer to do it now this is saying if the message does not start with prefix is not going to register it at all and if the bot sends a message with the prefix starting it will not interact with it now you need to do const args equals message dot content dot starts with uh config dot prefix dot length now there's an easier way of doing this so we need we can just come up here to cons prefix equals config.prefix.link now this we can just delete this and just put prefix here now that's a lot simpler now you need to do dot split do quotation marks need slash plus then after that you need to do semicolon preferred to do it instead of not now you need to do cons command equals args dot shift need to do quote bracket ah parentheses sorry about that then dot to lower case and c's again then the semicolon now this is saying let's say for instance our command is pink and then it would send pong let's say you do slash ping capital it'll still reply with pong so it's basically taking the command and putting it all to lower case so now what you want to do is do if command one two three three equal signs then the command equals ping so that's our command ping you want to do after it you want to message dot reply punk now you can do message.channel dot send and instead of reply basically send is saying and it's gonna put a message in the channel and then it's just gonna send it reply means it's just gonna re it's gonna add the user which we do not want to do and then put that at the end of it and then make sure to save it and then now let's see if it runs now you're going to run it with no dots and there the bot is online now we're going to do i pink all right so we got an error our areas dot split is not a function so prefix up here so we need to do so yeah let's just do this so we're going to delete that so we're going to do prefix dot length now we're going to try like that rerun it now we're going to do iping again still not so let me go back and see what's wrong and i'll be right back with you guys okay guys i just realized i did not mean to do starts with this needs to be slice now just save it and then clear then do node space dot now it should work see so all you really have to do is do all this it's not that hard now let's say you want to do another command all you have to do is else if command equal equals only two you only need to this time let's say i we can put in lowercase doesn't matter you do this again then you can do message dot channel dot reply hello now this is what reply does i'll show you sometimes it does not work sometimes it does so yeah let's try it do hi nope it does not work and it's because reply is not a function so reply it there's no need for channel i'm pretty sure so let's try it again hi and then it replays viper hello so that's the end of it and i'll hope you guys enjoyed it and i'll see you guys in the next video make sure to keep checking the channel to see other videos and i'll see you guys next time bye
Info
Channel: CodeViper
Views: 24
Rating: undefined out of 5
Keywords:
Id: W2xEm7gnL-E
Channel Id: undefined
Length: 6min 59sec (419 seconds)
Published: Mon Jun 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.