Build a DISCORD BOT with Node JS | Discord JS v13 #1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what is going on fellow web developers my name is tyler potts and in today's video we're going to be starting a new series on discord js version 13 with slash commands so i need a discord uh bot for my surfer currently i only have me six uh very good awesome bop but i'm very limited to what i can do without paying extra and i could pay extra to support the developers who have done a really good job and i probably will oversurface but for my server and for the the love of learning and teaching others i shall be creating my own bot to do everything everything we needed to do it's going to be leveling up it's going to be giving me updates it may do quizzes i don't know we came up with a big list of things we wanted to do on a stream the other day and they are now inside of notion and i will show you those as we're going through and what we're working on but today's video is going to be focused on getting the foundations laid the base set up we're going to get our bot ready from discords uh we're going to get our token we're gonna basically set up a node.js application and we're gonna install uh basically get our bot in our server ready to go maybe with one command just to test out so we can know it is working great so guys if you are ready for this do not forget to leave a thumbs up and we are about to get started on a new journey in discord js okay guys so now we need to go to the discord developer portal to actually create our application now to do that what you want to do is head over to discord.com for slash developers for slash applications if you're not logged in it will ask you to log into your discord account once you're logged in you'll be able to see the screen icon without strelexia as an application of course now to create our application what we need to do is go to new application and give it a name i'm going to name mine go ct but you give yours any name you desire click create and here you can change the icon or you can get the name or whatever for now we don't need any of this that's all fine we don't need to go to off to and we need to basically select bot and down here we can select the permissions we want and we're going to give it administrator which is eight which is great then let's go over to bottom we actually need to create a bot so let's click add yes do it and then it's going to create us a bot now we can gift the bot a different username if we want but i'm going to leave it the same we're going to need this token for later but for now just ignore it i am going to turn off public box i only want it to be able to go on to surface i invite it to for now and then if we go down here you can see there's two things here this one presents intense which can track the presence data and then surfer members so we want it we're probably going to need both of these later on down the line so just click those on and turn them on however if you don't think you're going to need them then you don't have to open one now let's go back to oauth2 and i just realized i need to click this again and click administrator because um i've i forgot that resets when you click away and then we need to copy this link and that's going to invite our bot to our discord surface so let's copy open up a new tab and paste hit enter and now you can see it says go ct bot connect to discord and we're going to pick our potsy coding cafe i'm going to click continue and it's going to ask me what are the permissions i want i want an administrator i trust my own bot i mean as long as nobody else packs it which i doubt they will we should be good let's click authorize now this is quite ironic it's asking me if i'm a human while i'm creating a bot um i am human thank you thank you for noticing and then here we are so you may now close this window is now done look how cool the little stars look anyway so if we go over to here bot testing you can see on the right we actually have ghost ct who is inside our inside um our offline stairs so he's currently offline so we need to get them online i'm also going to give him the role of bot boys in my surfer there's no real need you don't have to do that it's just because that's where my bots go so bop boy is here and he's currently ready to be tested but we need to actually set up a node.js application so let's close this and let's go down into a folder so i have an empty folder here i'm going to open up with official studio code you can use any text editor official sewer codes as my preference and before i do anything in here what i need to do is open up the terminal and write npm init hyphen y and now this is going to create as a package.json file obviously if you do npm and it says this does not exist you need to install node and npm you should just install node 16 version 16 or above because it has all the features that discord fee 13 uses so once we have our package.json you can see in here i'm just going to rename this to bot because i like naming my bot it makes sense to me and then we can just delete these scripts for now um we'll add a custom one in there soon and there you go that's what we need in our package so i'm just going to open up my terminal again and what i'm going to do is say npm install or just i and i'm going to install discord.js and emf i will explain what these do when we come around to them obviously discord.js is the um the package we're using and dot e and fee is well dot e and v so i'll see you on system okay now that it's done what i'm going to do is also run npm i but this time hyphen d to install a depth dependency and it's going to be node 1. now node 1 is going to allow us to restart our surfer without having to restart our server it basically restarts our server every time we make a change to our files so there we go if we just clear this that should now be done so let's close that down go into our package and you'll see here we have two dependencies and one depth dependency so now that is done we're going to go in here and we're going to create a bot.js file and we're going to get a client and some intent so i'm going to say client intents from or sorry is equal to require and we're just going to say discord.js so we're going to get client and intent from discord.js we then want to also do require dot ianfee dot config so what this could do it's going to set up process dot ian for your process process dot e and fee dot token or whatever we want to use so we can actually get stuff from a dot emp file and there you go we don't need to set up our actual client so i'm just going to use lowercase client and we're going to say it's equal to a new [Music] dot a new client and then the options will be in here and we can say intent and we need seven contents now what are intent so this is new in discord version 13 i believe and intents are basically the functionality your bot has so here we can say intents dot flags dot guilt and what that does is basically say we want access to guilds which are surface so we want to have surfer functionality we then want to say intense dot flags dot guild messages now what that's going to do is give us access to the messages inside of our client and the client is our bot so inside of a guild we'll be able to get the guild messages and there we go so we have those three things we now need to actually log on we need to be able to go here so we need to say client dot login and this will log us in but as you can see this requires a token um which is a string and obviously the token is from our bots and you can see here now i'm going to click to refill this so you can see it but i'm going to refresh this and regenerate after so you cannot use this token don't ever let anyone get access to your token because if they do they can control your bot and do god knows what with it so i'm going to hit copy and i'm going to go back in here and i'm going to create a new file called dot env and in here i'm just going to say token and i'm going to set that equal to the token just like that and then close that down and then this dot ian fee will now be we'll be able to access it so what we can say is process dot e and fee dot token just like that and that will give us access to our token now if we go to our package.json we can now set up a new script and this script is going to be called defeat for development and we're basically just going to say nodemon so the package we installed earlier bob.js now what this could do is it's going to basically every time we make a change in here it's going to update automatically for our server so we do not have to keep running it over and over again so let's say npm run dev and that is going to start our bot just like that now how do we know if that's working well if we come back into our bot testing or our surfer you'll see our bot is now online he's no longer offline he's online but if we want a more official in the terminal we can actually do something called on ready so we can say client dot on and you can use once which we'll call it once which is probably the better option to use so we're gonna say on once ready um we're going to call an arrow function that says console.log ghost is online just like that and now if we go back where's the error unexpected token that's fine if we save it should fix that issue and there you go you can now see it says ghost is online and if we go back to our area obviously notes changed here but ghost is still online meaning he's still working which is great but ghost can't currently do anything he can't reply to us he can't message and i'm not going to leave this tutorial without showing you how to at least get a message so let's go in here and let's say client dot on and now we can say message create so when a new message is created we can pass through a message which will be the message that has been created and we can say if message dot contents content dot starts with and now we can give a prefix here which i'm going to use this little back tick or not little back tick this little arrow uh the greater than sign i believe or less than one of them is less than one's great fan and i just know it's one of them but we're gonna have that sign and then we're just gonna say if message dot content dot sub string and we're gonna say one which is going to remove the um this element this prefix from our message it's equal to and let's just do this default ping or pong ping as ping isn't it so if we're doing a ping message we're gonna say message dot reply and we'll just say pong just like that and there we go that should now give us a good message to go on so let's go back to discord oh i just refreshed discord don't know why hopefully it doesn't take too long to refresh i i felt like i was refreshing my brows so i'm obviously so used to web development and here we are so now if we just said ping nothing's gonna work but if we now do this and ping and hit enter you can see we get pong so we went ping test you can see note works because it only works with the first value which is fine but i'm going to show you how to actually properly handle both uh text messages or message uh commands and also slash commands so we're gonna add slash commands to this later video um so yeah guys if you learned something new in this video please leave a thumbs up obviously we're going to be doing a lot more of these series we're going to be doing a bunch of different features we're going to be doing even voice features so i want to be able to go into a voice chat have ghosts jump in the voice chat and give me some responses when we speak now that's i've never done that before so i don't know if it's gonna work but we'll find out but anyway guys don't forget to leave a thumbs up smash that subscribe button and if you're new around here don't forget to check out the links in the description you can join our discord surfer or you can even become a member of the channel to support the channel so guys thank you for tuning into this video and peace [Music] you
Info
Channel: Tyler Potts
Views: 3,217
Rating: undefined out of 5
Keywords: webdev, javascript, css, sass, scss, js, vuejs, vue, reactjs, website development, website design, app dev, app, app design, app development, mobile app, native, web developer, app developer, developer, programmer
Id: Qc9uPgGmQ7I
Channel Id: undefined
Length: 13min 29sec (809 seconds)
Published: Tue Oct 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.