How To Make A Discord Bot

In This Article You Will Find The Exact Information On How To Make A Discord Bot & Interact With Several APIs. Start Making Your Own Discord Bots With Easy To Follow Instructions & Video Tutorial.

How To Make A Discord Bot
how to make a discord bot

Discord is a free and open-source communication platform that enables its users to chat via text messages and voice calls.

Discord users can also create and use their private Discord server bots. These are automated tools designed to perform specific roles assigned to them by their developers.

Bots are an essential and fun part of Discord.

If you’re reading this post, it’s most likely because you’d like to learn how to make a Discord bot for your personal use.

You will find a collection of ready-made bots for you to choose from at the official DiscordBots website or you can develop your own.

Below, you’ll find a step by step guide to walk you through the entire process.

Read Also: 8 Best Doscord Bots To Enhance Your Discord Server

Prerequisites To Make Your Own Discord Bot

  • node.js
  • Notepad++ or any other text editor. Windows Notepad will also work fine.
  • A Discord account
  • A Discord server to test the bot

How to Code a Discord Bot

A Discord bot is basically an “automated robot” that connects with your server and acts in response to specific events.

You will notice bots showing up in regular online channels, and can be identified by their blue “bot” tag.

The typical Discord bot comes with some background code/programming that directs it on how to respond whenever it encounters a user-specified trigger.

Put simply, when something occurs on the platform, your Discord bot recognizes it and then responds accordingly. 
You will get to program those responses.

1. Download The Node.Js Software and Then Create a Discord Account:

The Node.js system is essentially a free & open-source JavaScript runtime which is essential for coding your Discord bot and making it work.

You can download it at the official Nodejs website and then install it before we get you started with learning how to make a Discord bot.

Moreover, the process of learning how to make a Discord bot really begins with creating a Discord account and connecting it to your server so that you can assess your bot.

Perhaps you haven’t created your Discord account yet; visit the official Discordapp website to open one.

If you already own a Discord account, simply sign in and then launch the server where you want your Discord bot to exist.
Also, you will need text editing software, like the Notepad++ program for the Windows OS to help you with your coding.

2. Creating Your Discord Bot:

Next, you must create a “program” on the Discord platform so that your Discord bot can function.

This next step on our guide on how to make a discord bot might seem a little tricky, but it really isn’t too difficult. 

The objective here is to receive an “authorization signature” for your bot so that the Discord platform can distinguish your code and unite it with other user bots connected to its servers.

You can start by visiting the Applications page under the Developers’ menu on the Discordapp.com website discordapp.com/developers/applications/me.

Log in to your account and then navigate directly to the list of applications in your account.

Select the New Application option to get started.

select new application

Name your Discord bot and then click on the Save Changes button.

3. Getting Your Discord Bot’s Authorization Token

get the authorization token

While still logged in, look in the App Bot Userbox for the "Token: Click to reveal" link. Click on it and you will discover a text string. 

That string of text will serve as the unique authorization token for your Discord bot which will enable you to send code to it.

It must not be shared with anyone else — that unique token will allow the owner to generate code for the Discord bot; therefore, anyone who has it will have direct control over your Discord bot.

Fortunately, if you suspect that your token is compromised, the system will allow you to quickly create a new one using the “Generate a New Token” link located directly beneath your unique user token.

4. Sending Your Discord Bot to Your Server

The next step on this guide on how to make a Discord bot will require you to scroll to the App Details box where you'll discover your exclusive Client ID – a long series of digits.

add a bot to server

Copy those numbers and then add them to the link, in the space where the word “CLIENTID” is written.
See the example illustrated below:

https://discordapp.com/oauth2/authorize?&client_id=CLIENTID&scope=bot&permissions=8

Your final URL must appear with your unique Client ID number written in it rather than the fake one used here:

https://discordapp.com/oauth2/authorize?&client_id=000000000000000001&scope=bot&permissions=8

By copying that link with your unique Client ID number onto your web browser, you will be automatically directed to a web portal that will enable you to tell the Discord program where it should send your bot.

You will know the operation was successful when you launch the Discord app or via your web browser.

You will be notified by the channel that your bot has entered the room, and you can also observe it displayed inside the menu on the right underneath the listed online members.

5. Create a “Discord Bot” Folder on Your PC

You should also create an easily accessible folder for storing all your Discord bot files on your computer.

Give it a simple name like “MyDiscordBot” so you will know exactly what it’s for.

6. Launch Your Text Editor to Create Your Discord Bot’s Files

You should create 3 separate files for your Discord bot via your text editor.

Paste the following code inside the first file:

{
“token”: “Your Bot Token”
}

You can substitute the “Your Bot Token” phrase with the token earlier generated on the application page of your Discord bot.

You must ensure that the token is contained within the quotation marks.

You can then save that particular file inside the DiscordBot folder you created earlier on your PC, with the “auth.json” filename.

You must also ensure that it is saved in the .json file format instead of .txt because it won’t function as a .txt file.

Create another file, and then insert the following code:

{
“name”: “greeter-bot”,
“version”: “1.0.0”,
“description”: “My First Discord Bot”,
“main”: “bot.js”,
“author”: “Your Name”,
“dependencies”: {}
}

You could choose to substitute the name of the code author with anything you want; you could also alter the “description” into something else.

This file should be saved inside the Discord bot folder as “package.json”.

7. Define Your Discord Bot Code

You will have to make yet another text file, which is even more important since it will control the behavior of your Discord bot.

You must also be quite familiar with using JavaScript to gain complete control over your Discord bot.

However, if you’re a newbie to the world of coding and still want to learn how to make your own discord bot, simply copy & paste the following code into your Discord file to create a straightforward Discord bot for welcoming you to your server:

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.yourusername + ' - (' + 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;
           }
     }
});

8. Launch the “Command Prompt” On Your Computer and Go to the Discord Bot Folder

command prompt discord bot

It is very easy to get to the Command Prompt for your Windows computer by clicking on the Windows logo button and then inputting the phrase “Command Prompt” within the field provided.

As soon as it opens, type the letters “cd” and after that, your Discord folder’s file path.

This is done to alter the line of the command prompt to accommodate your Discord folder’s file path.

9. Harness the Command Prompt for Installing Your Discord Bot’s Dependencies

The time has come to utilize the Node.js. program.

Within the Command Prompt, that contains the file path to the Discord bot folder, enter the following phrase: “npm install discord.io winston –save.” 

This is done to automatically install the files you need directly into your Discord bot folder.

10. Run Your Discord Bot

Here is the final step on our guide for learning how to make a discord bot.

You should try running your Discord bot by typing “node bot.js” within the Command Prompt (first ensure that the Discord bot folder is still connected)

You should then return to your private server to sample your Discord bot by sending commands for it to run.

If all goes well, your Discord bot will immediately respond to any coded messages you have sent to it.

Well done! You just created a Discord bot!

The Round-Up

After reading our guide on how to make discord bot, this task should no longer pose a problem to you.

Go ahead and enjoy the endless Discord options available to you with this useful knowledge.