Develop a Discord Bot in 2023 Using Node. js | Erik Petersson | Skillshare

Playback Speed


1.0x


  • 0.5x
  • 0.75x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 1.75x
  • 2x

Develop a Discord Bot in 2023 Using Node. js

teacher avatar Erik Petersson

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

    • 1.

      Class Introduction

      1:54

    • 2.

      Chapter 1 Overview

      1:24

    • 3.

      Tools: Node.js & Visual Studio Code

      5:57

    • 4.

      Creating a Discord Bot Application

      4:36

    • 5.

      Creation a Discord Server

      1:57

    • 6.

      Bot Invitation & Folder Creation

      6:55

    • 7.

      npm Installation

      7:03

    • 8.

      Chapter 2 Programming Time

      1:43

    • 9.

      Start & Stop Node Server

      4:35

    • 10.

      Comments Within Programming

      4:21

    • 11.

      Node Variables

      6:14

    • 12.

      Console.log()

      4:40

    • 13.

      Discord Module

      7:24

    • 14.

      Discord Client Intents

      9:12

    • 15.

      Ready Event & Login Function

      7:14

    • 16.

      Message Event

      10:01

    • 17.

      Writing Commands

      7:23

    • 18.

      Token Security

      7:53

    • 19.

      Class Project Overview

      2:24

    • 20.

      Task 1/6 [PROJECT]

      3:30

    • 21.

      Task 2/6 [PROJECT]

      8:39

    • 22.

      Task 3/6 [PROJECT]

      6:44

    • 23.

      Task 4/6 [PROJECT]

      7:57

    • 24.

      Task 5/6 [PROJECT]

      2:34

    • 25.

      Task 6/6 [PROJECT]

      6:12

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

93

Students

1

Projects

About This Class

Develop a Discord Bot in 2023 using Node.js programming language. Node.js is JavaScript programming language but it is used as a server-side programming language. A server-sided programming language is used to create API calls, connect to databases and routing. Discord Bots rely heavily on API calls. With the Discord.js module we can easily create API calls to get a Discord Bot to interact within a Discord Server.

If you want to learn how to program your own Discord bots then this class is made for you. Class is made for beginners in programming and programmers with some experience.

Meet Your Teacher

Level: Beginner

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Class Introduction: My name is Eric and I'm an experienced developer when it comes to various programming languages such as Node.JS, JavaScript, C-sharp, etc. And I created many different kind of disk or bots before and many full-stack web applications using different frameworks. And I have a few years of teaching experience on Skillshare and Udemy. In this class, you will develop a disk about using NodeJS programming language. Now j is, is JavaScript but used as a server side language. Their basics are important and that's why this class is simple and made for beginners to start programming discard boats. You don't need any prior programming experience at all. You will be using the GIS and Visual Studio code within this class. I will cover how to install both of them. By taking this class, you will develop a disco, bought it on your own. This cobalts make your Discord server management easier and being able to create your own disk robots. You can get what you want for your server by learning a programming language Node.JS, you open up new doors for future skills, such as first stack web development, game development, and other kinds of software applications. Because a programming language like Java, NodeJS is very universal and can be used for many different kinds of projects. The class project focuses on you using the key skills taught within this class, such as extracting data from the object returned from events, programming at reading documentations. And those are very important for programmers. Remember that there is no time limit. So studied at class at your own pace and re-watch the lectures if you need. And I will see you in the first lecture within this class. 2. Chapter 1 Overview: Hello and welcome to chapter one. Chapter one is the non-coding section of this class. What this means is that we are going to have five lectures that are non-coding and chapter one. And then after that, Chapter number two begins chapter one. And we will begin by installing Node JS and Visual Studio Code and go over what NodeJS and vicious Jericho days. Then we will move over to beginning to create a new Discord bot application on Discord developer portals. The third lecture, while we do need a discord server, and I will show you how to create one. Then we will move over to invite thing that the school board that we created by going to disco developer portals. And then we grab an invitation link, modify it, and invite our bot to the Discord server. As well as we will create a folder and the app.js file that we are good to use when we develop the bot. And lastly, we are going to run NPM installation, which concludes npm init and NPM installation Discord dot js. This is the non-coding section, seems to because we're not writing any code, we are simply setting up the project for success. 3. Tools: Node.js & Visual Studio Code: Hello and welcome to this lecture. The objectives within this lecture is to install NodeJS and vicious do the code. And I will also give a quick explanation what NodeJS and what visual Studio Code is. The most important part here is the correct links because you're going to download something and install it. The way we hundred per cent have the correct links for the software needed within this course. For a NodeJS? Well, this is what I've done. I googled NodeJS and you can say the first link, no, js.org, that is the correct link. But let's take a few seconds to explain and go through what NodeJS actually. Well, in very simple terms, NodeJS is JavaScript, but it is a server side language. Nodejs is JavaScript used as a server side language. So you can connect to APIs, to databases, create a back-end for a web site that is oversight in very simple terms. We will be using Node.JS to create the disc about because it is a server side application. Nodejs. Select the recommended version, and then you open the installation. When it's done, it'll go to your download folder or you simply click it is sometimes it's a little bit slow, so I have to go to my Downloads. So if I go to Downloads here, you can start and you click Next. Accept the terms, the license agreement. Click Next and then you can select your path, but I'm going to click Next. This is fine. You can click next here. This is something you shouldn't check. This box here is to all necessary tools like chocolate, like what is that? Probably nothing good for your computer. So leave that empty next and then install. Depending on what kind of computer you have. Like if you have an SSD, it's going to be quite fast. I already have a bot, so close applications. You can use to that. That is probably something you want to have if you download, you get for the first time and installing. I ordered had a NodeJS application up and running. So basically as close to it. That's why I got that message. If you have an HDD, it might take a few minutes, but I haven't SSD, so it's quite fast. Finish. That's about it. So now we have no adjacent stall and the only thing that you need to know about it right now is, like I said, it is a programming language. It is JavaScript used as a server side language. And we will use it to develop the bottom. And let's head over to Visual Studio Code. I've done the same thing here. I googled Visual Studio Code, and that is correct. Link. Ambitious to decode is the editor where you will write your software. And it is a very, very nice editor. Wave write the code. It is very simple, it's efficient and it's fast to load the code. And you can type in a terminology to start the Node server and you have debugging, etc. It is a very all-around good editor, especially for beginners. They're very good. And here we have some options. You have Mac, Linux, windows, windows. So I go into download the stable version. You can see an image here of what the editor actually looks like. The IntelliSense is really nice. You can see there are some extensions and Python is extremely popular all around. Python is a very nice language. But we're using Node.JS. We get this very strong language as well at it is very popular. In my downloads. I have historical, they're going to double-click it. Accept the agreement. And I don't like to add anything here. I like to keep them empty because you can just search for beach to the code and you will find it on your computer. Go next and install. And this should be quite fast. Installation. Like I said before, if you have an HDD, it might take a few minutes. And that's pretty much it. And I will not launch Visual Studio Code. That is pretty much all I wanted to do within this lecture. Now we have the things installed. And if you would run into some problems when you start with the probe with a programming, you might need to restart your computer for the Node.JS to work, but I've never come across that issue before. So hopefully you will not get the tissue. Otherwise, just restart your computer and it would work. 4. Creating a Discord Bot Application: Within this section, we're going to create the boat on Discord developer portals. And the objectives are that we will first create application basically in user. But this usually isn't about Not yet. And we're doing this on Discord server developer portals. We are converting the application to reduce cobalt. And then we need to allow the intense and settings so that the bot can actually receive messages and handle the events. Here we are, disco developer portal. I've already Google this. You need to click this link. And then you need to have two applications. You need do need to be logged in. As you can see, I need to be logged in. So I'm basically going to scan the code from my phone because I'm logged in on Discord on my phone. There we go. Now, I'm logged in on discord, the web portal, and I get access to all applications that I have created, which is only one. What you need to do. To go up here to the right corner, the web, the web browser new application, click that and give it a name. Well, I think the best name would be hello world, simp. Simply like that. Then I agree. Alright, so this is the application that I was talking about. It is currently not to Discord bot, but it is an application. If you look here, you have tags except you have description. Well, nothing here is really that important. And you can of course, delete application. But why would you want to do that? We're going to make it a bot. Here is the section. On the left side you see a tick box here and it says build a bot. Click Add votes. Yes, do it. Loud application is a d.School, bob. And that is what we wanted to happen. And you can see the view Tolkien, this is my password and I am going to copy that and save it. But if you forget to token, you can simply refresh the website and Risa token. And here is your new password. So it is really easy to get a new password if get it or if someone hacks your bot, you can use Qlik. There is a token. Alright, here we need to look at some settings and intense public bought public boss combated by anyone when unchecked early eukaryote this bottle servers. Well, I only want, well, I basically want it to be private. So we're going to uncheck that multiple scopes where we're not using there. So we can leave this as it is. Here comes the intense that we need for the body to function. Depressants intent. Check that the server members intent, check that message content intent. Object that we will be using the message content and presence. Or perhaps only the message content. But if you wish to further develop the boat and test things out, you need all these three because these are the main components. Main intense, you could say. But it just got both. Here. We have some permissions, but we're not really giving the boss some add main powers, so we're not really in the need for specify any of those. It is basically something you have for larger boats that are public that you used in multiple channels. I mean servers that, let's say streamers are gamers are using or moderators, then this becomes more important. But for us, for the basics, it is not important because we need to focus on the important basics. 5. Creation a Discord Server: Welcome to this lecture. Within this lecture, we're going to create a discord server. And the only objective that we actually have is created this conserver, as simple as that, right? Okay, so we're going to create a discord server. And this requires you to actually be logged in on your Discord account and have your Discord open. And you can see, I have to actually free service here. And we're going to create a new server. That is very simple. If you go to the bottom of your servers, you see it says Add a server. Click that. Here are some templates that you can use. A template for us, it has no purpose. We can simply create our own for a club or community or for me and my friends. Well, I'm going to segue for me and my friends, but you can select whichever you like. The name is going to be. Eric's gloss. Simple like that. Create. And we don't really need to have like a name to like your image. And I go to place it right here. Okay. Well, we have a tech channel and I can write hello. And we have a voice channel. This is pretty much all we need. We only need like a text channel. The voice channel is needed, but we can't simply keep it there. Jed, general tech channel is what we need. And inside here is where we are going to write the commands to test the bot and get application up and running and reply to messages, and so on. 6. Bot Invitation & Folder Creation: In this lecture, we're going to invite the bot and create a folder and the files that we need. We will begin by going to the disk, whatever portals, because we need to invite them to a server. And to do that, we need to grab the invitation link and modify your client ID to match the idea of our application. And then we can invite the bot, which is quite simple. Then we move over to creating a folder on your desktop is the standard folder. And then we need to open Visual Studio Code for first time. And we need to navigate folder. We created an open that folder with Visual Studio code. So now we're inside a folder and then we will create a file with the name app.js, which is a JavaScript file. And the name app.js is important, it is to entry point. And ArcJS means that JavaScript, right? Okay, it's time to invite at the disco bought our server. And a way to do that is to head over to the cobalt application we created called Hello worked or whatever name that you gave it in the previous lectures. If we go over here, we're going to use the description to store the invitation link. And what do we need to invite the disk abort. E is to copy your ID below here, paste it into description, and then Save. Right. Now you need the invitation link. That link is found in OF2. Then you click, learn more about our F2 and a new window pops open. And then you scroll down. I will scroll it. Slow you so you can see where I'm heading. We're going down to the URL example. This example is used to invite your bot to the server. And it is like the most basic link you can have with a bot, and that is precisely what we need. You can see you have advanced or both authorization. But honestly for a beginner, this is a little bit difficult and it is quite unnecessary because we don't need it at all. Perhaps if we were to create a very advanced but in the future shorter than my might be worth it. But currently, no, it's not worth it. Right? I did copy this link. And then I head back to my general information where I have the description and then I paste the link and save this link. We need to modify. In order for this to work. And you can remove the Add permissions. Now, you notice it says Client underscore ID and the link is equal to a large number. Replace that large number with the ID that you paste it here, or copy the application ID below. And then you replace the id with the idea of your body. What do you do then is copy that link. Go to a new tab, paste that link. And suddenly, you see here, we can add this application to a discord server that you have permission like Admin power of ad server that I created is called Eric's class. And the discord server you created might have a different name. But select that server. Nonetheless, authorize. I'm human. And then you might need to select, like all images with an airplane or Something like that. You probably know that I'm talking about, right? I have Discord open already inside my server. And you can see that this guy bought was successfully added, used to make sure that it is actually the scope. But you can see in offline here that this cobalt helloworld has this kind of blue tag. If the white text that says bot, that is a disco ball. Alright, so the boat is invited. And now we need to create a folder and then open Visual Studio Code. And I do this by going to desktop. And you can see I have some files here, but you can ignore them. On your desktop or another location that is easily accessible. You create a new folder and give it a name. Give it a name, hello world bot. Inside this folder, we are going to create a JavaScript file. But we're not doing the normal Create New and text document and change the file extension. We're not really doing that. Instead, we are opening Visual Studio Code. And it is most likely going to open an existing project. So I will click File, Open Folder. Click the folder that you created and it is on desktop. Click helloworld bought. Right? I'm going to close that. Right. So okay. Where we are right now is that we are inside a folder that we use created ad on the left side here you can see it is marked in blue. Right-click you file app.js. This is very important that the name is app dot js. App is the name of the file, which is short for application. And it is used whenever we're running NPM installation. It is going to look for entry point app.js. And ab.js basically means that the file extension is a JavaScript file. So press Enter. And inside this file is where we're going to write the code. But we do have one more lecture when it comes to the non-coding part. And that is what we're going to do within the next lecture. 7. npm Installation: In this lecture, we will go over the NPM installation. Takes that you need to do within this lecture is that you need to run npm minute to install a project with a product settings and so dependencies. And one dependency that we are going to use and save is the discolored js module. So these two are actually the main commands that you need to write. So if you forget, something happens like in the lectures and you can see what I'm writing. Then these two are, the convention is to write npm init to initialize a new project. Npm install this code dot js to install the decoder js module so we can access the API calls, create an application creating client, and everything. That is with the Discord bot. So these could have GIS is the Discord bot basically. Alright, okay, so what you need to do now is that you need to head back to Visual Studio Code, open that up. And this is where we left off. You had created your app.js file. But you don't really need to look at that right now. We need to open up the terminal, or we can call it a console. It is basically the same thing. And in the console we are going to write the commands. And permitted and NPM installed this code dot yes. You can see at the left side here, it is marked in blue. Is basically your project, your folder. Right-click Open in integrated terminal. And I can see if I can make it bigger. I probably can't. Alright, let's see here. Let me just fix that. Once again. We can keep it like that. Alright, so what we need to do is that you need to write npm in it. And it is automatically go to the text that it is node. And if it doesn't actually recognize node or NPM as a command, there, perhaps you need to restart your computer. Probably used to do manual, manual restart. Then it doesn't really recognize node. And then start Visual Studio Code as an administrator. Alright? But for me it works. So what we're going to do is that when you have written and per minute, you're going to set the settings of the project. And you can see that this is the name, but you can change that if you want. You can write anything and press Enter. But I'm going to leave it blank because I liked the name helloworld bought. And then for the version, you can press Enter description, Eric's class project from Skillshare description. And I will show you that when it is created, I will show you the description and these values. Alright, here comes the important part that I spoke about earlier. Entry point. Make sure that impact thesis. It says app.js because Andrew point is going to be your app.js file, which is like the main file for this project. So if it doesn't say app.js, app.js and hit Enter and test command. You can skip that by pressing Enter Git repository. Skip that by pressing Enter keywords. Well, skip by pressing Enter. Once again, author, work, give it your name. License where we don't really have any license. So presenter, is this okay? Yes. Press Enter. And there we go. Package.json just arrived. This is your project like the project settings, the name diversion. Well, you can shake it. You can change it here. If you'd like. I can change to eric peterson. Now. That's completely fine. I can close that and open it. And it says, Eric Peterson. You can change it as much as you want and a version, etc. But this is basically what we need. Right? Let's move over to installing this goo.gl layers. And I want you to keep an eye on these properties. You can say license scripts, main, description, except these are properties and read text here is basically a value. The value of the property. When we installed this quadrature is a, another property is going to be added. That is going to be called dependency. And it is going to have a value that's going to be the Discord dot js version. Okay? So remember the command that was in the slideshow or PowerPoint presentation. You can call it whatever npm. Install, Discord dot js. When I press enter, it will take a few seconds. Right? Okay. You can say that a dependency was added. These go dot JS with this version. This quadratic is here. The blue one is a property of dependencies. This is the value that is the version of this goto j is currently at it added a package like JSON file that is a very complex and large and we're not going to even look at it is we don't need to. You can say node modules was added. There's a lot of stuff there, but we will use these curvatures in the upcoming lectures. This is pretty much it for this lecture, we installed by running npm minutes, followed by npm install. This quadrature is to install. This could attest that we need to develop the bot. 8. Chapter 2 Programming Time: Hello and welcome to chapter two. And chapter two is programming time. We're going to start writing some code to get to the bottom up and running and to finish the development of this cobalt. So these are the things that we're going to do within this chapter. And we will begin by looking at Node JS variables as a basics about Node JS variables of R, let and const keyword. Then we will move on to creating a variable that is going to store the discord ab.js node module. That is important because we need that in order to create our new discord, the client, which is going to be the disco bought. The client we will create in the code is to disk, but you could say. Then we will move on to adding a ready event to capture the state when the bot comes online. And we also need to have the login function for that to work. So we will be able to login the boat and get the bottom line. Then we need to create the message event that is going to be fired whenever someone writes a message in the Discord server. That is where the magic happens. Every follow up that lecture with how to write commands. We will write two simple commands for today's cobalt. And in the programming part, we will finish off with some security about the token as unsafe to talk. And that is what's in store for chapter two. So let's begin. 9. Start & Stop Node Server: Hello there. This is an added lecture and this is going to be about start and stop being a node server. This operate, operation varies depending on your operating system. Windows, Linux, mac acceptor. To start running a file, you write the command node followed by the name of the file, which in this case is app.js. Node. App.js executes a file. And that file is going to be this cobalt, and that's going to be a node server, you could say to exit, to stop the node. So if I'm running for Windows, Control plus C stops server. For Mac, I believe it's Command plus c. And Linux, I believe it's the same for Windows. Not sure exactly for a boon to the logic is that node followed by filename and extension, Of course. And there are few things that I'm going to mention. I going to say this cobalt, I go and say node server. I'm going to say run the code, run the file, execute the code execute a file. And all of these things refer to the same thing, node app.js or node project, or j is just the name of the file. All it means is that we're going to compile the code. Basically it is, it is a translation. And that is what we do with start stopping the node server. We compile the code. You run, the file starts to server. And you need to do this by opening their console, the terminal, right here we are. I have a few files here, which I'm not going to show you the code because that would be a spoiler. In the left side here. I'm going to right-click open in integrated terminal TO open up the terminal. Now I'm inside the folder and I get access to the files. Like I said before, like in the beginning of this lecture, if you run the command node followed by the name of the file, you start running that file. And that file is the Discord bot. To run another file, we can write node variables dot js, which is a test file, which is a test file that gives an error. Simply because we are trying to do something within that file that isn't allowed. And that is going to be something within this course that I will show you what class you could say. And in this case, I didn't need to exit because there was an error. I can run Node project list dot JS, that is not a final executable. But nothing really happens biggest, nothing in that file keeps the server up and running like the disco ball. You can use the up arrow keys and down key in order to select a command that you previously run. At. A nice trick that you can also use. If you would like to execute the project list file. You can write project like bro like that. You press Tab and then it automatically finishes finding the closest file. The closed. Like when the name matches what you use wrote like pro project or JS. And then you can press tab again to loop through the files. And by doing so, we can select what file we would like to run without writing the full name. So I can basically write Node a, press Tab. And that's node app.js. I press Enter and the boat is now online. So that is how you start and stop the Node server. And that is going to be something we do a lot for this Discord bot. 10. Comments Within Programming: Comments within programming is very useful to describe the code and to leave notes for yourself or for other programmers. We will begin by creating a new file called comments dot js. This is a JavaScript file, but we will only populated with comments. There are two different kinds of comments that you can use. One comment is a single line comment. It makes everything on that line ignored by the compiler. What does that mean? The compiler is basically translating their programming language, the code as you are written into a lower level programming language so that the computers can communicate with each other. E.g. the computer doesn't really communicate in JavaScript. It doesn't really send the JavaScript code over the internet, use like that. It compiles it into a different language that is lower level depending on where, how, and when acceptor. But we're not going to cover that. But just understand that the compiler translates to code and everything that is a comment is going to be ignored. So you can write whatever you want and it will not affect your program at all. The first comment you create by writing slash times. This is a single line comment. So basically, let's say you have created a small function that evaluates if the user exists in a database, you can write something like this. Function value. If user exists in a database table or ready or not, that describes the code, but we don't have any code there. But this is used in showcase how comments work. And a second comment can spread through multiple lines. Not used one line. You start with slash, asterisks. It becomes green, complaints. Asterix and green. This is a multi line comment. But you can clearly see that this line of comment only covers one line. You can do something like this. And then you can do this. Leave this area, MT. So here you can leave a lot of texts about the function. Let's say that this function requires a lot of explanation, and therefore we have a multi-line comment. Everything that is here is going to be ignored by the compiler. When we execute a file. I will use Commerce throughout the class, and I hope that you will use comments as well to describe your own code or leave a nice little messages. You don't need to use notebook or write on paper or save it in Google Drive or notes or anything like that. You can simply create a comment inside that for grabbing me. Fine. Leave it like this. Don't forget to change the name of the function. Or you can write like this. I have trouble with task number three, teacher for health. Later on. That is something you could also do, leave notes for yourself so you can do whatever you want with the comments. These are nicely to note for yourself. Explaining code, leave notes, etc. 11. Node Variables: This lecture is made for absolute beginners in programming. So if you already know some about variables and how variables work within programming, you can skip this lecture. But this lecture is to give you the basics of variables because there are three types of variables we are going to cover, which is the variable using the var keyword, let keyword and the const keyword. And you can see that I've written on the var keyword, it's an old keyword. And then let e, I have written and new improved. That basically means that, well, LET is a better version of var and cons. We will also cover that because Cohen's d is very, very, very important to use within programming because you cannot change the value of a constant variable. And we will look at that within this lecture and then we will use the const keyword more often when we develop the disk bought. Alright, I will cover some basics about variables in Node.JS within this lecture, functions and events acceptor, we will look at when we start developing the disk cobalt. I will use the const variable quite often in the programming. And it is important to understand what is the difference between a normal variable and the cost variable. So I'm going to create a file called variables dot js, which is essentially a test file. And you can see I have it console open. And if you don't have the console open, daycare, right-click opening, integrated terminal. Right? So there are three types of variables. All of them are set, but two of them are better. Compare it to one of them. The first one that is, isn't really good for back-end programming is to var. This is a variable using the var keyword. But I will not cover exactly what the problem is. Part of var has some issues within itself. So the better way to create normal variables is to write the let keyword. Okay? They are pretty much identical, but in some more advanced instances, there is issues with the var variable. And we give the arrows or wrong code, but that is fixed by using the let keyword. So let a variable is an improved version of var variable. But there's one thing you need to know. If you plan on developing front and web applications, like you plan on starting web development. When you're programming in the front end, the var keyword has better support. Compare it to the let keyword in front end web development. Var is what you're going to use any backend, let. It is better for back-end and var has better support in front that these are two normal variables that can use. They pretty much do the same thing. They hold a value. And you can change the value in exchange to value by writing name is equal to Adam, and last name is equal to constant name. Well, var name. Let's give it a name one. Let's see if that's better. Yeah, I probably shouldn't use named because it is probably a key word. I forgot about that. Alright, what we've done so far is totally fine. We can declare the variables and we can change the value of these two variables. The var keyword and let keyword this variables. It is totally fine to change the value. If I write node variables dot js, you guys say that nothing really happens. But if I were to create this variable, h is equal to 26. And I run the code again. You can say it is completely fine because we declared a variable. What is the power of the constant variable is that you cannot change the value of the test ban declared. Let's say it's my birthday today. And h is now 27. Is this allowed? We're going to get an error. And if I scroll up, Let's see. Okay, It doesn't doesn't want me to scroll up. It says there's an error within this line of code. It says assignment to cause a variable. That is the problem. It doesn't really say much a parson debt, but basically, you are not allowed to change the value of the constant, variable. So that is what we are going to use within these Discord bot. Because if we create a new client with all the intense of partials, well, we don't really want anymore to change the value of that client to, let's say, a word, which is possible here. We want to make it a cost variable so that you cannot change the value. 12. Console.log(): On piece of programming code that we're going to use within this course is that console log statement. What does console.log do? Well, it prints a message to the console. That is all it does. But why do we use it? That is the most important question, right? So what we can do things here to print data to the console to see if the value is what we expect. Let's say it should be a value of a name, but maybe it becomes undefined, becomes empty, comes to Boolean, we get an error, then we see that something is wrong. So we expect to get the proper value as well as the type is being correct, because we might expect a number that should be yellow in the console, but it turns out to be green. That means that it is text. So the number 60 is text instead of an actual number. That can be a problem within programming because different types don't really match, that, doesn't really mix that well. They tried to take a string and save it and try to run math, except that we would like it to be a whole number, a correct number, to see if the type is correct and the value is correct. We don't really see that much in this cobalt. So maybe sometimes we do need to use for that specific reason. But something that can also be quite nice for disk robots is that we print an error message to the console so we can read the message and fix the code. So let's say we create a route like he's tried to catch method, yes. And you have a specific L statement or something like that that catches whenever something doesn't really go planned. And then we can fix the code. Something that you can do if, let's say you develop a website, which will obviously not doing within this class. But what you can do is that you can write a message to the console. When a user or customer buys an item from your webshop, that is something you can do. And we will mostly focus on use printing some data to the console and see what a database, that is what we will do. This is going to be very, very short because there's only one way to actually show you how console log works before you use it. And that is simply by writing a few letters. A few characters could say, I need to open up this terminal. I right-click opening integrated terminal, make it slightly larger. Then we open up the variables dot js. This is going to result in an error when you run the code. So I am going to comment out the h is equal to 27 because that isn't allowed. Instead, I'm going to write console log h. And then I will also console dot log their last name, last name. And then we're going to start the node server, very variable such as. You can see this is the difference. Because green is typically the color whenever a property has a value that is text, that is inside JavaScript Object Notation or JSON object. You could say. We will look at that later on in the class. But you can see we'll console log. I logged the value of the variable age, which is 26. And then same for last name. And you can of course write console.log. We didn't number. And with a text yourself, you can write hello. Then I run that file again. And that is pretty much it. You're printing a data to the console. 13. Discord Module: In this lecture, we will look at the disk module variable. And this disk module variable. Well, it's going to be a variable that contains the discord module. And it is going to be a constant variable because we don't want to change the value of this variable. We will also look at some documentation about Discord before we continue with the next lectures, programming the intense and partials, etc. So this is going to be about one variable only, which is the disk module. This is where we previously left off with. Their file is created with the disconnect yes, installed, etc. So we will be doing now is that we're going to start writing some code. And within this lecture, we will only focus on one line of code and then look at the documentation. So open up your app.js. Now, what we need to do is tell it we need to create a variable that is going to be like a reference to the disconnect j is that we installed the discarded GIS node module. To do that, we simply create a variable. We're going to create a variable called Discord, and that is equal to require Discord dot js. This line of code is the desktop GIS node module. So what we can do now is that we can look at this chord. So let's see here. Well, you can see there's a lot of things here that exist. We haven't really added anymore CO, so these are the things that I would like to go through when it comes to the documentation. Like you can see, there's a lot of things here. And some of them we are going to use, and some of them are beyond the scale of a beginner. Alright, so let's take a look at the documentation. This is a link to the documentation. And you can simply go to a disco dot js. If you simply use Google Scholar GIS. You can see it looks vastly different. That is because you have to go to this link here. Click up here, select this code actually is. And here we are. It says old, and I'm not totally sure if they're going to update the documentation, but currently this works. And this is where we read the documentation to find out how a classwork, how events work, what exists, like what properties do we have of a class, basically an object. You can say here, it says clauses, I can expand it or close it. Functions we can close clauses is something we got to use. Client is a class that we're going to use. Then of course, guild member is also a clause which is going to eat a data of a specific guild member and order guild member objects. One we will be looking at is called message. And message class is, well, it, basically it's an object. Class and object are pretty much similar. This is representing a message on discord and that is precisely what we're going to use. This discount bond. And this message object has a property called author e.g. it has a property called created at created timestamp. It has edited at, if the message has been edited, it has something called content. Let's see where it is. There it is. Message content. Is the content of the message. E.g. the message is hello everyone, I'm new in this server. Or you could say, tonight, I want to play some Counter-Strike with you guys or you up. That is the content of the message. And that is something we're going to use created at the time when the message was sent. Create a timestamp. Pretty much the same thing, but it is a slightly different format. Well, some are like this is a Boolean is true or false if the message delete table. And there's a ton of things you can find here. As our V that is also quite cool, is that even though the message object has properties, well, the property itself can be an object. So we have some circular references. And I can have a short lecture about circular references. But what you can take away from this is that we are going to look at the documentation to determine what we can do. And it will also be lucky in that class project to use a property that is an object to find out like use details in the console, you do not need to do too much coding, but you'd need to use it to see for yourself what kind of data you can receive. And of course, the message is also going to have a method. You can say method or function. It's pretty much the same thing. And you have the method called Reply. And we'd reply. We can reply to the user. So we can sell back a message. We're going to create a command. And if the command is like help, the bot is going to reply weird, Well, my name is this and these are my commands and this is how you use them. There are a ton of stuff here, and remember this is just one class of menu you can see when I scroll down and then I scroll up, you can say how many classes they are. So it is a universe of what you can actually achieve. But we will look at the basics, because if you understand the basics, that you will most likely be able to comprehend the document, the documentation, and you will be able to figure things out and create some standing desk or bots. 14. Discord Client Intents: Within this lecture, we will be creating a new client. And the client is essentially the Discord bot application. Not to be confused with the disk bot application on the web reporters, that is merely the account you could say. What we're going to create the stria client with, which is the programming part. And we will once again use the constant, variable, constant. We will read documentation how intense and partials work. And what we will also specify within this client is what intense we need for this bottom function. And we also need to specify the partials. And partials. Make sure that we received the full data. And then we will once again read documentation. Right? It's time to create the client variable and specify intense and portions. And we need to go over what the intense and partials are. But first, I'm going to create the client variable that is going to be there. The type const, use this code because where we are declared this client variable, we don't want to change the value of it. Comes client is equal to nu, these scored the client. Then you need to write parenthesis and brackets. The intense is a array and they will be specified in here. If that pop up, texts can be removed. And then you specify or Schultz. Just like that. Alright. This is the basics of these client variable. In the intense, we were specified in terms, of course, at partials, we have specified a partials. What are intense and partials. Gateway in intense were introduced by these scores. So bot developers can choose which events to bot receives based on which data, data it needs to function. We need the message, the gill object. We need to specify that intent and partials. What, what is the purpose of partials? We are accessing the event and accessing the data, but we're not accessing the full data. With partials, we will be able to receive the full data of the objects returned from each event. E.g. the message that we have looked at, the message is an object that we will receive. And there are other types of OBX we will receive. Good member, object, shadow, guild member, message, user, etc. We would like to receive the full data of those events. They have full data of the object. So we are creating a new client with intensive partials needed for this, both the function and once again, partials make sure that we received a full data of the object returned from events. Let's look at the documentation here. I have the line selected and it extends the base client. There isn't really anything we need to look at here. Apart from here, you see it says new client in paddies. It is options, just a parameter. Type client options. Click that right. Okay. Properties. What are the properties for that parameter? What are the options? You have shards, you have allowed mentions, you have rest. Well, there are some things that you're not probably going to use, but they exist for larger bolts. Of course. What we will be using is the option called partials, which is an array. And here you see, Hey, I'm not a text about it. You can read it. Alright. That's to do with the data. We need to use it to receive the full later. And then intense is something we will also use, intends to enable for this connection, well, basically to receive events. So let's head over to another documentation that is the official discourse developer portals documentation, list of intent. Alright, in this list, gills is one intent. Guild members is another intent. And you can see we have more and we have one called direct messages and message content. As you can see what you can access within them. We didn't use where you can access these events. Had indirect messages. So you have these events that we will be using a direct messages, message content, guild members, gills, and gild messages. You can say when it comes to partials here, we want to receive uncashed users and messages. And the parameters you can have user, channel, guild member message, reaction. You can scale your event. Thread member. We will be using four of them, and that is user, channel, guild member and message. Alright, let's specify the intense first. Discord or gateway intent beats, dots. And here you have a lot of intense. And the first one is, let's see where it is. It should be up here, direct messages. And what you can do is that you can copy direct messages or more times. And instead of writing direct message theory, right? Message content. Guild members because we would like to access guild members message content. We would also like to access gills. Even though you might not need all of these four digit code. But if you plan on continued developing these two is good, but then these are the standard, intense and they are really important. Otherwise you bought were not work. And you might be wondering why this is going to make sure that your desk bot is working for whatever purpose that you are developing. And if you make it more advanced, then you need to add more intense. Partials is called. Partials. Should be capital P or shows an enum that Shannon. And then you can copy this three more times. We have a partial called guild member, message and user. This is the structure for the client. The intense at a partials. With intense, we make sure that we can access the events that are going to be fired. Every partials, we make sure that we get the full data of the object returned. You could of course, read more about an experiment, more about entails and partials, but these are the basics and they are a little bit complex. So it's good to understand that if you have this, you bought this going to be able to do a lot of things. 15. Ready Event & Login Function: In this lecture, we will be looking at the ready event and then again function. And these two work hand in hand. You need to have the login function working in order to use relevant because the red event is going to be fired whenever the bot comes in line. To get the bottom line, you need to send your token to the login function. So red event is fired once. Unless you stop the application and started again, then it's going to be fired. But it's only a fight once when application is alive, even if the application reconnects, is where it is only going to be fired once login function takes your token, the password, and we will once again look at the documentation about the red event, how we find it, and then login function, what parameters it takes. Let's start with reading the documentation about client and the derivative at a login function. If we scroll down, you can see that we have properties, methods, and events. The first we will look at reading. Because reading is an event. And you can see there are quite a lot of events here. If you scroll down, you have ready. And I click that and I automatically get scroll down and assess the red event emitter when a client becomes ready to start working. Okay, so when they're both gets online, you could say when it is ready, like no error. It gets online, basically it works. Then the red event is going to be fired. And it has a parameter of type client. This is important, this is very important. The parameter you get in return, you can give it any name. But let's give the name client, that is of type client. And what this does kind of object to get in return. Well, it is the client, your Discord bot. So I did open client in a new tab. Alright, let's see, this is the object that we get returned whenever the red event is fired. And you can see that it has properties. One property we will use is the user. If I click on User, it is of type client, user. And on clients use, we have a property called tag. So that means that if you write client or user tag, we will get the name of the disk. But let's actually close down and do that before we look at the login function. Alright. I will add a comment first. And comments are ignored by the compiler, is green lines. The red event captures the state when a bot gets online. And to do that, we write client that on ready. Remember that parameter is called client where you can aim it, see, you can name it. A bot to can name it whatever the parameter name can be anything. This is error function. This client. Well, this client is going to contain data about the discussion board. What you can simply write is console dot log. This boat is now online class. Remember, client had a property called user and you had a property called tag, and that is the name of the discount bond. Next, sexually run the code. Remember to right-click open any integrated terminal node after j is to run the file. And nothing really happens. Why is that? Well, the thing is, without a login function, this event is never going to be emitted. This is going to be executed, but the file pretty much ends there because this is never going to be fine. So let's go back to the documentation. Client methods login. Let's see here. What does it look like? It takes a parameter. This is a string which is the password of our disk or both, and we need to get that description is logs the client in establishing a WebSocket connection to this chord. You know what, we can copy that. And a parameter is a token, and it is the type string token of the account to login with client login token. But this isn't really going to work because token isn't really our password. To get the token, we need to head over to Discord developer portals. So I'm going to close down the documentation now. This code developer portals applications at a word. We need to go to the bathtub, Risa token. Then you copy the token, replaced the token. Here we go. And now we are going to attempt to login the boat. I run Node.js. And suddenly you can see that the red event is emitted. This post is now aligned. And then the name of our Discord bot, that is the red event and the login function. So now we have a robot that is actually online. The server is up and running the node server. Then this cobalt, it says it is on line. Hello, world is online. 16. Message Event: Welcome to this lecture. This lecture is about the message event. And the message event is fired whenever a message is written within the text channel, within the server, or in a direct messages, but we're focusing on messages inside a discord server. And we will block both from the code execution because I will show you a problem. Because the boat is going to spam endlessly replying to a message that we will stop that from happening by blocking boats from code execution. And if you have any problem with the data, then shake your intense or go to the web portals where it created this cobalt and check if an intent is unchecked or you might need to restart your computer for something to work. But if you get any problem, object intents, we have come to the fun part now, which is where we will actually make the bot interacting with us. And that is through the message, create the event. Back in the documentation to the client class. Last time we scroll down to find it, they're ready event, if you remember that. But this time we are looking for a specific event called message create. If I click that. And it clearly says that message create the event is fired were emitted whenever a message is created, data, we get in return, opened it in a new tab. We get a parameter in return, just like we did with irrelevant. But this is going to contain data about the message that was created. But there's one thing you need to understand about the objects that we get in return. You don't simply get date of the message created. You get data off so much. You get data about the whole guild. You get data about the owner, you get data about every guild member in the server. You get so much data. It's like it's like the tip of the iceberg it gets, so when you write, when you read this, and to prove that this is the message or vector T is returned, you can see how many properties, there are many properties and there are many methods. Remember, each of these properties have properties on their own. So it goes even deeper and you can find so much date days later. They're like probably 1,000 lines of data, at least from the message object on its own. But we're not really going to deep, we are simply using the basics and the most interactive parts for the method. We are going to use the reply method. And we will also be using the message dot content. So let's look at what message or content is. The property called content on message is basically the text or the content of the message, which is very, very basic, like if someone says hello, that is the value of this property. Right? Let's move over to reply method. Reapply. It sends a reply message to the user. We're not going to use this because this is a promise and we're not using that. We are simply using message dot Reply. All right, so enough talking. Let's get back into the code. And I'm going to play place the message create event here. We had a comment. Clients dot on, just like we did with the red event. But instead, you are going to write message create. The, remember, the return data is a message. You don't actually need to give it an MS search, but I do that just because that is the class that is returned. So you can actually write a message to reply. You have written a message. This is actually going to work, but it is going to spam. That is something we're going to fix as well. So restart the server. If you have installed Node moan, UK, you don't need to restart the server. But I decided that we're not using node month for this class seem to because I would like to teach you report that the basics about programming because sometimes you need to restart, like save and restore it for it to work. So we're doing it at the basic way. Moving over to this chord. If I write a message, suddenly you see that both begins to spam. If I wait a few seconds, it starts to continuous spam. I stopped a Node server by pressing Control C on Windows. On Mac, I believe it's Command C. But anyway, how do we stop this issue? We can stop this issue. I adding an if statement that is going to return if the user who wrote the message is a disco ball. So the way this work is if you look at the method here, I write a message, both the texts that it tags me and replies to my message. But now the boat has written a message. So it is going to detect that it created a message. And it is good to tag itself and say you have written a message. It takes itself and replies to itself. And it's continuous like that over and over again because the message create currently isn't limited to real users or these cobalts. It is basically any user at all. So the body is going to continue in an endless loop, spamming for playing itself out. A way to fix that, to stop that from happening is to say that this part is not going to reply to a user if they use. So who wrote the message is a discount bond. That is a very, very simple. You write if an if statement, if message dot author. If that is equal to true, we simply write return. I go to run this code. And then I will take a look at the documentation. How I know that we can use this code. I started and I can write hello and the butcher play once. Great, The code is working. But why is it working? If I go up here, this message object, if you look at what I wrote, message, that author dotplot. So I need to find a property called author. And inside author, I need to find a property called bought. That should be a Boolean that is either true or false. This is the author. It has a property called boats. Boats is a Boolean. Whenever or not. They use this about. So it is true if the use is the Discord bot and it is false if the user is not a discount bond. And if you happen to have any issue like you don't get any data returned or it doesn't detect a message, create the event. Perhaps you do not have the correct intent either here. Or it might be that on this co-developed portal, I got application. It might be that if you go to both, I think it is, you might have forgotten to check any of these boxes. This one should be blue, it should be checked. 17. Writing Commands: Hello there and welcome to this lecture. In this lecture, we are going to be writing commands. This means that we will reply to a specific message. Maybe you've seen disco balls to test, lack help command or invite command or time command or me play music command acceptor. We will create a very basic command for this cobalt. Or actually we will have two commands and those are held at Hello, use to get things going. And there is a problem that we are going to face, but we will solve that quite easily. And that has to do with that. We need to convert the user input to lowercase because NodeJS is case sensitive, so they use input has to become it to lowercase for the commands to work properly. In this lecture, we are not going to read the documentation at all. What we're going to do. Instead, we're going to add a comment before this line of code so that we don't run this code anymore. What we're going to do is that we're going to create an if statement to check if the user is writing a specific command. Right? If I were to write ****, I want the bot to only respond. Say like, well we have these kind of commands. And if I write, let's say I write help with out the exclamation mark. It is not going to respond as well. So let's fix that. Right? First, create an if statement. If message dot content that is equal to L. The boat is going to reply with saying, this boat has two commands. Exclamation mark health and exclamation mark. Hello. Hello isn't developed yet, but we will fix that. Right? Okay, let's run node app.js. It over to discord. You see nothing happens if I write anything. Alright, ****. Nothing. But if I write exclamation, mark help. Suddenly later bought response. That is perfect. That is precisely what we want. We only want the bot to listen when we write a command. But we have a problem. Nodejs programming language is case sensitive. That means that if I write helping caps, the boat is going to not answer at all. And that is because we're trying to see if the input matches this. But since it is case sensitive, this text here, exclamation mark help, is completely different compared to this hair, that is all capitals. That is how programming works. They have different values for the character. So this, these are completely different, different values. So to avoid this issue and to avoid headaches and makes us more smooth, we can convert the user input two lowercase letters or characters only. So we can convert exclamation mark health too. Lowercase l. That is quite easy. You need to create a variable. I'm going to create a const variable. I will call the message lower case. That is equal to message dot content dot to lower to lowercase. I made a mistake there, lowercase. But this is going to do is that it is going to convert the use of message, two lowercase letters or characters. So down here, instead of checking if message or content, we will be using our newly created variable. Message. Lowercase. I hit Control C to stop the blood from running. I execute a fire by writing node app.js and now comes to test. Is it going to work? Yes, it does. Because no matter what we do, all characters that we send are going to be covered lowercase. And that's actually add the last command that's going to be hello. And we don't really need to have an if statement, so we are using them more efficient way else-if message, lowercase variable equal to Hello. We are going to reply with hello on you too. Simple like that. If I stop the server Control plus C, then righ, right node app.js. Press Enter. We have the help command. And it has a halo command. Perfect. And of course they work with capital. If you write like this, it still works. Made it consolidated bit smaller. This is the basics of a disk or bought. And hopefully now we have this code. Voltage is up and running and you have these cool, yeah, pretty cool. Reply messages. You could say. You could expand it to detect when a mess, when a new user joins your server. And there are a lot of things that you can do. And I've saved some tasks for you to complete in a class project. 18. Token Security: Something that you don't really see a lot when it comes to simple disk bots security. But we have one part in this programming that is going to need some security. When it comes to developing applications. More or less. Some applications maybe have Sarah security biggest. It doesn't really need any. Let's say a front-end website for the sign only know backend. No need security in all forms except for F a disco boats. If yours is simple, you might not really need much security apart from your password. And that means that security is not one priority for back-end development. Extremely important that you have security for your database connections and user accounts acceptor. This is like the safety equipment. If you're using a chainsaw, it is going to prevent a lot of bad stuff from happening. It is going to lower the risk of injury by a lot. But it's like the annulus jobs, you lower the risk of injury, but you will never be able to erase the possibility of enduring yourself, like removing the danger completely. And that is exactly the same in programming. You can limit how much problem is going to be caused if you don't have security. By adding security, basically, we have no security. A lot of things can happen, but if you add code that's going to prevent bad stuff from happening, well, maybe if something would happen, it would have been minor. So that is okay. That is pretty much what we're doing. We're hiding the token in an external file that is going to help us a little bit when it comes to security, it will be more difficult to steal your password because it is hidden inside another file. And I think that we should start this lecture and just go through the security. When it comes to security and programming, it might seem like a very boring subject. And I know that a lot of projects like students or a smaller company, so or even the audit companies, they don't really seem to care that much about security. It's like it's, it's called, it's just a waste of money. But the thing is, security is extremely important. But you will never be able to create application that is 100% secure. But there are a lot of things that you can do to lower the risk of having a hack or lowering the risk of losing data or leaking data, etc. Just like you to work industry like a job. I've had. This all mean, it was extremely dangerous. But we did pretty much everything we could to lower the chances of getting injured. And that resulted in a lot of changes. You can see it as cutting with a chainsaw, without any safety equipment. Well, if something happens, well, it's going to be extremely terrible. But if you wear the pants, the boots to help the safety glasses, you are lowering the risk of injuring yourself by a lot, but you will never remove the risk completely. As well as there are some rules like you like how it should be like chest, the chest level you could say, and not above your head except that is extremely dangerous. So everything is about lowering the risk of anything happening. So what we're going to implement is that we're going to store this token in an external file. That isn't like the safest method you can do in the world, but it is going to lower the risk of you're both getting hacked. Because if you would like to post your code to get some help or use Screenshare or just anything. Well, if someone sees your token, they can steal it and do horrible things with a disc ball. But if you token will be removed from the file completely, it will be much more difficult to hack your bot because they cannot actually see your password. Because the password is saved within external file. That they are not really accessing because they can't see it when you post your code. So I need to create a new file called config dot json. File is json object like this token, followed by your password. Alright? You can close the file. And we're going to create a variable that we're going to, we're going to write config. We got to that just named variable, and we will use that variable, the access to the password and then login to this cobalt. And we do it up here. And it is as simple as that. Const. Tolkien is equal to require dot slash, config dot json. If everything is working with the correct name, config, I can write node app.js and the boat is going to come a line. This is the token is invalid. That is because we need to give it a name, config my bad, run the code again. And now it works. I use misspell. I usually use the name token, but in this case, I chose the name config. You can clearly see if I were to send this code someone and they would help me. They cannot actually access my password because it isn't here. It is saved within the external file. What we did is that we basically added on safety equipment, we're going to be cutting with a chainsaw and we are lowering the risk of anything happening by a lot. And if anything would happen, then we have some safety to protect us. And securities, very much forgotten in some cases. So it is very important that you actually focus on security whenever you need. But for this code boats, if you're not developing extremely advanced is cobalt that connect to databases or saves data than safety isn't needed so much because there's nothing to protect really. But if you were to try and become like a full-stack web developer and you study back-end development and security is literally like 90 per cent of your code. That's how it should be. 19. Class Project Overview: Hello and welcome to this lecture. Now, come to the part where it's time to develop the cross product. This product is going to further expand the discussion board, but more importantly, it is going to teach you some more things. So you will expand your knowledge. That is more important than having a bot that as many functionalities because we the knowledge you will be able to develop the functionalities that you need. For each task. There are six stars care. This is a brief explanation or Canada detailed explanation about each task. I will also have a lecture where I complete, let's say this task. In a lecture after that, I complete this task and I talk a lot and explain how it works. So even if you manage to complete this task on your own, I would highly suggest you to watch these lectures because I do explain quite a lot that you probably didn't learn yourself. Where if you're a beginner, if you have done programming before, then you might be more comfortable. But I will suggest watch those videos, lectures. I mean. So read through this and if you have any questions, then just let me know. This is more description about the class project. And when you're done or if you have completed the one task to task, three tasks or all of the task, then you can upload your project in a discussion or you can use to upload a project. And I think that's pretty much it. You should start with the class project whenever you feel like it. And if you get stuck, ask for help. Or you can watch the six lectures after this one, because those are the ones where I explain about each task. 20. Task 1/6 [PROJECT]: This is a first task and we're going to print the message object to the console. And we're going to find the object on the documentation. The first part, let's actually print object and see what we're working with. We have used a print method, print technique before. It is console.log. And the way you print the object to the console is for writing console dot log. This is going something to the console. And that something is the message object that we get in return. That is this parameter up here. If I print the message, you're good to go to the console. And I started, but for me, that file isn't called app.js anymore because that is a file that is the original file of the discard. Both. My file is called Teachers Project and yours is probably only called Project ab.js in the source code that you can download, right, with a terminal, open a console, you could say, right, node teachers. In my case. And then I can hit Tab and it automatically finds the file. Then I press Enter, right the bottom line. All I need to do is to write a simple message. You can see in the console, the terminal here. We printed a message object. And if you take a close look, you can see there are some properties here and they have a value. The green is a string, the yellow is a number. And yellow when it says false or true is a Boolean. You can see some are undefined. That's okay. This is what I wanted you to do. Previously. The message of yet object displayed much more properties and data. But now, in order to find all that is possible, you need to head over to the documentation, the inner product list. You have the documentation here, the link. I already have the link open. And that is here. This is what I wanted you to do to open up this message object in the documentation and view the properties. You can see it does quite a lot here. And these are data you can pull from the message object, and that is what we're going to do. This is the first step, is to find the message object printed to the console and read the data that is returned. 21. Task 2/6 [PROJECT]: Right, this is task number two. We would like to find out some more data about the author of the message. By doing this, we are going to the same link in the documentation as before. We're going to print some properties to the console. You may write a message again. However, I still have their message will be printed to the console. So if you do not have them message printed to the console, you can simply a right and a message and you will get fresh data. Alright, let's see where the message begins. It begins here. The properties we would like to find Is tag, discriminator and username. And that is here. This is the author. This is the user, right? You can see we have ID, that is my ID, my account. I am not the body. If we look at we have the username that Eric Peterson. We had a discriminator, but the tag isn't actually here. The reason why is because all the data isn't always displayed. You can find that piece of information. If you go to the message object. Remember, we have a property called author. That is an object itself. So essentially what we have is that we have an object inside an object. In the documentation. You click the author, the author property. You can clearly see that it says the type is a user, which means that it is an object. The click is used for here. And here you have the user object. At this user object contains properties, and those properties can be an object. But we're only looking for the attack. But you can clearly see that the tag name. Let's see. If I go back to No, it isn't actual name. We are looking for the discriminator groups. If I go back, we have the discriminator here. We have the username here, and we have the tag. So by reading the documentation, we know that we can access the tag username and discriminator by accessing the author object inside the message object. Even though we do not have the data here printed, we know that it actually exist. So now we need to write some code. I'm going to my, let's see here, I am going to the code here. And I will write console.log, and I will copy that three times. Let's read again egg, discriminator and username. First, we need to access the message so we can write message in all three of them. Remember, we're not accessing a property directly onto the message. We're trying to access a property inside the author objects. So we need to write message dot author. And by the way, author is a property of message, but the property we're looking for is not inside message, it is inside author. If a write-off author on all three of them, not activity, it is called author. Then we had the tag. Use the name discriminator. We can simply use commented out, so we don't actually print this message. Once again, I press Control C to stop execution. And then I press the up arrow key to run the latest command which is going to execute this file. And now I can simply write a message again. And we should see in the console that this is my tag. You can add me if you'd like. This is my username. This is my discriminator. So they use today plus the discriminator is basically the attack. But you can clearly see that we can actually find data of the user, the author of the message, by looking at the data and digging deeper into the data and reading the documentation. In this task, I did forget to actually add they're created at for the message that author. So I've already completed a project, but I use noticed when editing that I forgot to add the createdAt. Property number four, I should have used that. Let's just add it and I will explain a little bit how it works. If I simply console log message to the author and then you write dot, you will be able to access all the properties and methods that actually exists and decorate the death is down here. And I am going to print to the console what is created. That actually is because it's good to differentiate. Like if you compare it to create that on a guild that we are using later on in the class project. It's good to understand what you are trying to find the createdAt date for. But if you find the createdAt date for the message, the message was created like 10 s ago. But the author was that a user account created starting the Node server. And what I did is that I write, I write node is the right thing. Teachers project manually. You can write teacher like that and press Tab. And that tries to find a file with a matching name. This cobalt is now online and I only need to write ASD. And you can see that now we get this date and it is purple text. And it's a date in 2016, so it's quite a while ago. And that date is the date I download the Discord. I created my first ever Discord account. And you can see that even though the message is created, now, we can find data that is from seven years ago. Something you can keep in mind when developing the disc boards. You can find data from many, many years ago that might be very useful today. 22. Task 3/6 [PROJECT]: For task number three, you're going to console.log and new user plus the member. Whenever you use a joint your Discord server. And it would help if you have a friend or a second account to help you out. You can take this link or you can go to the client class and look at the guild member at events. Let's actually go to their client clause. You can see that we have some events. We did use the event before called message create. This time we're looking for something called guild member AD. And you can say that this event is emitted whenever a user joins a guild, basically a discord server. And a parameter we get the return is a member and the type is a guild member and a description. Remember that joined a guild. You can click the gear. Remember, this is the object of the data returned. Find the tag. Let's see, tag is on, let's say guild member dots. User. Tag is how you can find who joined your server. This is my second account and I am logged in on Microsoft Edge, but it doesn't really matter what browser you use. But if you use two different browsers, you can be online at two different accounts at the same time, on the same computer. This account I will invite whenever I have added the event. If I go to the code, mine is called teaches project. Let's add the event. The event looks pretty much the same like we did here, except guild member AD and member reliant. On guild member add. The parameter is called member error function. Here we can simply write console log a new user or you can simply write member dots user dot tag. You can write this. And you can also write this. New user. Last member. Juicer joins your Discord server event. Okay? I restart, that is cobalt. And if you have node one, you don't have to. Alright? Well, I'm going to invite the second account in my server. I need to invite that account. And to invite Eric clocks. Invite people. You have write their name because they Eric test, there is my test account. You invite that. Then I go over to Microsoft Edge. You can see two online total two members join. If everything worked. We should be able to see AND consultant. Because remember we've printed the tag that we printed this message. Let's scroll up. Here we get the bot is aligned. This is the tag of the new user. You can see that in the bottom corner, small text. That is correct. And now it says new user added, then returns this. Then you say that it trains the members, count the number of free. And then you can see that it prints all of the members from the fetch method. And you might be wondering, why is this happening? Why is it printing? We didn't write a message. We simply added a member. That is because this, it was printed by Discord dot py. They're both but by discord when the new user joins the server. And this is classed as a message. So that both the texts, this message biggest, this message is not created by this cobalt. Then it simply runs this code. This code, you might be wondering why, why is, where is this coat color coming from? That these are the tasks that I recorded. First. I basically recorded task number three as a last task. And these tasks I did before. But anyway, you can clearly see that the guild member ad works. If you scroll up a little bit, the tag. And then new member, which is the id, essentially. 23. Task 4/6 [PROJECT]: This is a task number four. In this task, I want actually to find out the nave of the Discord server and a date when a discord server was created. And this is going to depend on a message object. Once again, I'm going to head over to teach this project. And to avoid clumping up like the console with lots of texts, I'm going to add comments here. And by commenting this out, the compiler will ignore the code and it will not be run at all. And I need once again to remove the commerce from the console log statement here and restart a bot. And I'm going to write anything. Right? Okay, so what we need to now again is the name of the Discord server. And this when the Discord server was created, can we find it by simply looking at the data here? We can't actually, we cannot even find a good object. What you could do if the intelligence works, you can write a message dots. Then you can scroll down and you can see that the blue boxes is a property and pink purple boxes are a method. And we are looking for a property. Educate clearly see that a lot of these properties here that don't actually exist when we display the date of the message object to the console. They are actually still there, but you can't really find them just like that. We are going to use the guild property because Guild is an object that contains the information about the digital service or guilt is equal to Discord server. Right? We did have a link to the message object. So let's look at the message object once again. Okay, The Message object, we did look at the properties and found something called guild and that exists on in the documentation as well. A click yield. You can see it says type guilt, guilt. The message was sent in. If in a guild Shannon. It doesn't work in a private message because we wrote in a discord server, so we get access to guild object. If you click that, it takes you to. This object called Guild, represents a yield or server on Discord. Efficacy it says it's recommended to see if a girl is variable before performing operations or reading data from it. But we know that the gill is available, so we will skip this, but keep that in mind. You can see that this guild object contains more properties that a message object. Essentially all the data about the Discord server, a advocates channel timeout application ID available, available. But we're looking at their name and create the debt. It can see created at here is a property that's read-only and it says the time the scale was created. That basically means if my server was created yesterday, it's going to display the date, or ten years ago. Or maybe actually not to discount, probably didn't exist ten years ago. But anyway, the name, here we have the name. If I click that, the name of this guild, and that is a string, and it's going to take us to a, another link that we don't need to go to. Because we know that string means text. The way this works. And why it is important is because if you have a bot that is inside the multiple Discord servers, perhaps in different scenarios, it would be wise to be able to sort out which discord server the bot is working inside right now. Let's say, it says like where I let ten people who are banned. But it doesn't say which server then you don't know and you will never find out. If I hit Control C to stop the file execution that node server, and then I'll restart it. Then I can write any message. And in this case, instead of printing the message object, we are specifically is printing the guild object inside the message object. And let's say the data is going to display everything. Or do we have to specify through the documentation? Once we go what we want to print out. We can clearly see that we have name here, eric class. And that is true that we would like to find created at. There's a lot of text here, so I'm struggling a bit slow. And it seems like it may not actually tell us where it is. Let's see here, it doesn't actually show us anything, right? So what we need to do, we simply need to write dot name. Hopefully this entire line, place name with dots created. And now you are going to hit Control C to restart the node server. If you have node one, then you don't need to do this, but we are not using node one within this class. Then I write the message again. Now we are printing the data. We want the name of the disk or service Eric's class, and that is correct. This is the date when a discord server was created, which is about five days ago. Okay? Number four is done. This is basically delving deeper into the object to find some more data about the server. And you can actually find out exactly which server is being written in when it comes to the message object. 24. Task 5/6 [PROJECT]: In this task, we are going to find out how many members exist within the Discord server. Okay? Okay. We will begin by looking at the documentation. So we can start that bought. Mine wasn't started. And right-click opening integrated terminal to open up this terminology, the console to start this over. Or actually I need to comment these out. And I would like to simply write console dot log. We are going to look at the message object, but we will be looking at the guild object inside the message object. If we go to the documentation, the message object, remember that the Discord server is within the property called guild. In Guild here we do have some properties. We are going to find out how many members exist through their member count. Members count. This is the first part. The second part we are using the fetch method. But chick members count here and eat these at type number. It is going to return a number, the full amount of members within this good. The data is actually quite easy. Message dot guild, dot member, member County. It's cold here, but didn't it say it says a member count here? If we go back to the code, this should print the number. And if I restart the Discord bot. Alright, so what exactly is it going to say? It is going to return a number. We are two members within the servers. So if I write anything, it should say the number two. 25. Task 6/6 [PROJECT]: Find out how many good moments exists within the Discord server for the message object. By using the fetch method on the guild members property. Now we need to delve a little bit deeper into the object. Because we cannot simply use right to count like this. We are going to console.log. So we can begin by writing that message. Alright? If we head over to the documentation of message, we already know that we need to go to the guild. Let's say gill should be there. Then I click that. Now we are in the game class. Here we used in the previous task, we used the member account. But now we need to fetch all the members and find out ourselves how many exist by looking at the object returned. This only works if you have a few people in your Discord server. If you have 1,000 people or 50 people, I don't believe it is going to print all of them. But you will be able to see how many exist. Under member count. You have a property called members. And that is of type guild member manager. If you click that, it says managers, API methods, forgive members and store that cash. Alright? This is the guild member manager. Okay? We have some methods. One of the methods is called fetch. If you click that, it says fetches members from a good. This is going to return a promise. And promises, we are not covering that much because we are not going to fetch a specific user. And that requires a little bit more logic. We are simply going to fetch all of the members. Message dot guild members, dot fetch. We are going to write it down, then end up catch them. If you look at the code, it looks like this then and I console log, console error, console dot log error, console error. Alright. If I restart to both now and I make the console a little bit bigger, I simply write a message. We do get an error. And the reason why is because we need to write dot catch instead of dot error. And you can clearly see it is quite easy to find out what the issue is because it points here. And it says error is not a function. Then immediately, you might think, Well, maybe I didn't misspell it. But you find out that it should be called, catch. This error. They both didn't deserve it, didn't actually start. To need to start this over again. Write the message. Once again, write it did print some data to the console. And if we scroll up until it says the number two, this is where we begin. Because remember the number two is this line, the message dot guild dot member count, right? And it says collection two. That means we have to give members. And the object is quite large. This is a good member with this ID. And I believe that uses actually me. And we can scroll down and find out. Go down a little bit slow and we're looking for so in green texts, because the green text is string and the username is equity. So that concludes the first guild member. The second guild member begins here. Scroll down. We will get the name of the Discord bot. Hello world. And you can clearly see that the user has the, has a property called bot that is equal to true. That is because the user is the Discord bot. But if I scroll up to my account in the data, it says bot is equal to false because I am a real user. This user is a Discord bot. That concludes this task. And the task number seven. When you're done, upload the product in a class, forum and share with other students and share with me. And you can receive feedback and you can give feedback to other students, et cetera. Feel free to upload your project whenever you want.