How to Create a Discord Bot?
For several years now Discord has shown that it is totally focused on continuing to improve to offer the best possible experience to all its users, becoming a platform that is now not only used by gamers. It is now one of the most used platforms for messaging, video calling and streaming between friends.
Discord's functionalities have been growing as the development team has improved the platform, but without a doubt bots are one of the most special additions to our product portfolio that we can find on this platform.

With a Discord bot users can do just about anything with JavaScript code. But if you have no programming knowledge, you have nothing to worry about. In this article, we are going to guide you step-by-step so that you can create your own Discord bot even if you are not a programming expert.
- Steps to follow to make a bot in Discord
- Download Node.js and prepare your Discord account.
- 2.- Create your own bot
- 3.- Obtaining the authorization token for your bot
- 4.- Send your bot to your server
- 5.- Create a "bot" folder on your computer
- 6.- Open the text editor to make the files for your bot.
- 7.- Define the code of your bot
- 8.- Open the command prompt on your computer and navigate to the Discord folder.
- 9.- Using the command prompt to install your bot
- 10.- Execute the bot
Steps to follow to make a bot in Discord
Download Node.js and prepare your Discord account.
Node.js will allow you to run JavaScript for free as it is an open source program, which is completely necessary for your bot to work. You can easily download it from the page nodejs.org (here)You must install it before starting the rest of the process.
As you can imagine, we also you will need a Discord account y your own server in order to test your bot. If you have not yet created your Discord account for some reason, you can easily do it from the Discord.com page. If you already have an account created, you will simply have to log in to your account and open the server on which you want to bring your bot to life.
You will also need a program such as Notepad++ in Windows, in order to work in a more comfortable and effective way the code of your bot.
2.- Create your own bot
Now you will have to create an "application" in Discord in order to make your bot work. This can be done in a very simple way, as the process is not complex at all. Here, the main goal is to get a "authorization token" so Discord can recognize the code and add it to your bot on your servers.

To do this, you have to start by going to discordapp.com/developers/applications/me (here). You should be logged in to your account so that you can go directly to your application list settings. Here, simply select New Application (New App) to get started.
You will have to give your bot a name and then you will have to select the option Save changes (Save Changes).
For the next step, you have to go to the right menu and select Bot. When you see the new menu, select the option Add Bot (Add bot) located under the option Build-a-bot. If you only have one application (the one we just did), then it will be selected automatically. Otherwise, you will have to select it.
3.- Obtaining the authorization token for your bot
In the App Bot Useryou have to search for the word TokenClick to disclose (click to reveal). Once you click here, you will see a line of text. This text will be the authorization token for your botwhich allows you to send the code.

It is very important that you do not share this token with anyone.The token allows anyone who has it to create a code for the bot, which means that anyone else who has it will have control over your bot.
In case you think your token has been compromised, you can generate a new token very easily. In fact, for security reasons, it is recommended to create a different token each month. by selecting the option Generate New Token (Generate New Token). After doing this, you will have your new token in a few seconds.
4.- Send your bot to your server
Now, you must go to the part where it says Application Details (App Details) and find your Client IDwhich is quite a long number. Copy that number and add it to the following URL replacing the part that says CLIENTID:

https://discordapp.com/oauth2/authorize?&client_id=CLIENTID&scope=bot&permissions=8
Remember to remove the part that says "CLIENTID" and put in its place your real Client ID that you have obtained from Discord.
Now that you have made this change, copy the URL that already has your Client ID in your browser to enter the page. This will take you to the Discord page so you can submit your bot.
You will know that everything has gone well if the page sends you to your application or server. The channel will say a bot has entered the serverand now you will be able to see it in the menu on the right side.
5.- Create a "bot" folder on your computer
After doing the above steps, also it is highly recommended that you create a folder on your computer, being a very easy way to replace your bot files.

Simply called "MiBot" o "DiscordBot" so that you don't forget what the content inside is about.
6.- Open the text editor to make the files for your bot.
Now, you will have to create three files in the text editor of your choice (you can use the one we previously recommended).

In the first file you will have to copy this code:
{
"token: "Your Bot Token".
}
In this code you will have to replace the text "Your Bot Token" for the token you generated in the previous steps for your bot. Make sure the token is inside the quotation marks. Now, save the file in the folder you created for your Discord bot. The file should be named auth.json.
It is very important that do not save the file as .txtbut you have to save it as .json.
Now, create a second file and add the following code:
{
"name": "greeter-bot",
"version": "1.0.0",
"description": "My First Discord Bot",
"main": "bot.js",
"author": "Your Name",
"dependencies": {}
}
This time you will have to replace "Your Name" with your name, plus you can also change the part of the "description" adding whatever you want about your bot. This can be useful for you to remember what the bot is supposed to do.
Save this file with the name package.json in the folder we created in the previous step.
7.- Define the code of your bot
We still have one more file to create, which is the most important because it will be in charge of controlling the behavior of your bot.

In order for you to truly have control over your bot, you will need to be familiar with the JavaScript programming language, but if you are completely new to programming and just want to do something, you can copy and paste the following code to make the following code a simple bot that can welcome people to your server.
Start of the code
var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
token: auth.token,
autorun: true
});
bot.on('ready', function (evt) {
logger.info('Connected');
logger.info('Logged in as: ');
logger.info(bot.username + ' - (' + bot.id + ')');
});
bot.on('message', function (user, userID, channelID, message, evt) {
// Our bot needs to know if it will execute a command
// It will listen for messages that will start with `!`.
if (message.substring(0, 1) == '!') {
var args = message.substring(1).split(' ');
var cmd = args[0];
args = args.splice(1);
switch(cmd) {
// !ping
case 'ping':
bot.sendMessage({
to: channelID,
message: 'Pong!
});
break;
// Just add any case commands if you want to...
}
}
});
End of code
As mentioned before, this code makes your bot able to respond to certain messages, specifically those that start with a character "!".
In other words, what we are doing is programming a bot to respond to the command "!intro"so if someone writes this on the server while the bot is on the server, the bot will respond with a scheduled message.
In the code we shared above you can see that the message is defined as "Greetings, welcome to the server!" (Greetings, welcome to our server!). You can change this message to whatever greeting you want to give. Just be sure to keep the quotation marks intact.
Now, you have to save this file under the name bot.js in the Discord folder we created.
8.- Open the command prompt on your computer and navigate to the Discord folder.
In Windows, you can easily open the command prompt or console very easily, just click on Start and start typing "Command Prompt." and then select it from the results that appear.

When it is already open, proceed to type "cd" followed by the path to your folder. This can be seen very easily by navigating to the folder and holding down the shift key while right-clicking on a blank area of the folder, then you can select the option "Open command prompt here." o "Open PowerShell here."depending on the console you use.
9.- Using the command prompt to install your bot
Now. you will have to use Node.js. At the command prompt, with the path to your bot's folder, you need to type the following: "npm install discord.io winston -save."

This will automatically install the files that were inside the folder we created for the Discord bot previously.
Also, you have to use the following command line to install some additional dependencies:
https://github.com/woor/discord.io/tarball/gateway_v6
This action should give you all the files you need.
10.- Execute the bot
This should be it, and now your bot should be running completely normally. To try to run your bot, proceed by typing "node bot.js" in the Command Prompt (be sure to keep browsing the path to your Discord folder).

Now, go back to your Discord server and try to test your bot by typing "!intro" or simply "!" followed by any message that is in the "bot.js".
If everything went well, you will now receive a response message from your bot.
Remember that Discord has a very large community of users who are constantly creating new things, including bots; therefore you will be able to create a large number of bots developed by other users. If you are going to use them, just be sure to give them the recognition they deserve.