Digital Marketing Agency | SEO, Paid Social & PPC

How to Make a Discord bot for Free

Share This Post

Discord has proved over the years that it is the instant messaging platform for not only gamers, but anyone looking to message, video chat, or stream with friends online. Discord Bots can help you do everything from automating mundane tasks to start playing music across your server, and in this article, you will learn how to make a Discord bot.

The main reason for using Discord Bot is because of automation, you can program one to do anything like anything that you can cram in some JavaScript code. You do not need any programming knowledge to get it done, either. This article will get you started making your own Discord bots, even if you have never touched a line of code before. Below are the steps to follow in making your own discord bot.

Discord bot

Step 1: Download Node.js and Set Up a Discord Account

Node.js is a JavaScript runtime that is free and open-source, and you will need it to make your bot work. It can be downloaded at nodejs.org and installed before you get started on anything else. You will also need a Discord account, and your own server to use to test your bot. If you have not created one yet, then head to Discord.com and create one. If you have one, all you need to do is log in to your account and open up the server in which you want your bot to live. You will also need a text editor program such as Notepad++ on Windows, to code with.

You may also like Download GTA 4 Highly Compressed Game For PC

Step 2: Create The Bot

It’s time you create an “application” on Discord to make your bot work. This requires a little work, but it is not too complex to do. The goal here is to get an “authorization token” for the bot so that Discord recognizes your code and adds it to the bot on its servers.

First, go to discordapp.com/developers/applications/me. Log in to your account and head straight to your account’s list of applications. Click New Application to get started. Give the bot a name, then hit the button marked Save Changes. Now, on the right-hand menu, click Bot. Once in the new menu, click Add Bot under the Build-a-Bot option. If you only have one application, the one we just made should appear automatically. Otherwise, select it.

Step 3: Get Bot’s Authorization Token

Here, in the box marked App Bot User, look for the words Token: Click to Reveal. Click that link and you will reveal a string of text. That is your bot’s authorization token, which allows you to send it code. Don’t share it with anyone. The token allows whoever has it to create code for the bot, which means whoever has it can control your bot. If you think the token has been compromised, the good news is that you can easily generate a new one with the Generate a New Token button. Markdown your token. You will need it in just a second.

Step 4: Send Bot to Server

How to Make a Discord bot

Now scroll up to the box marked App Details and find your Client ID, a long number. Copy the number and add it to this URL, in the place of the word CLIENTID.

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

The final URL should look like this, but with your client ID number in it instead of this fake one:

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

Copy the URL with your client ID number in it into your browser. That will take you to a website where you can tell Discord where to send your bot. You will know it worked if you open Discord in an app or your browser and navigate to your server. The channel will say a bot has joined the room, and you will see it on the right side menu under the list of online members.

You may also like PUBG Mobile For PC Using Tencent Emulator

Step 5: Create a ‘Bot’ Folder on your Computer

While you are doing that, you can also take a moment to create a folder in an easy-to-reach place on your computer where you can store all your bot’s files. Name it something simple, like “DiscordBot” or “TheBot,” so you know exactly what it is.

Step 6: Open Your Text Editor and Make Your Bot’s Files

Now you need to create three files for your bot from your text editor. In the first, paste this code:

{
“token”: “Your Bot Token”
}

Replace “Your Bot Token” with the token you generated earlier on your bot’s application page. Make sure the token is inside the quotation marks. Then save the file into the Discord bot folder you made on your desktop, using the filename “auth.json.” Remember not to save it as a .txt file, it won’t work if it’s .txt instead of .json.

Make a new file, and put in this code:

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

Replace the author name with your name if you want; you can also change the description to something else if you want something more in line with what you’re making, which will be handy for remembering what your bot is supposed to do.

Save this file as “package.json” in your Discord bot folder.

Step 7: Define Your Bot’s Code

There is one more text file to make, and this is the important one as it is the file that controls your bot’s behavior. You will want to be familiar with JavaScript to really have full control of your bot and know what you are doing, but if you are new to coding and just want to make something, you can copy and paste this code into the file to make a simple bot that will greet you in 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.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..
         }
     }
});

This code sets up a Discord bot that will respond to certain messages: Specifically, anything that starts with a “!” character. In particular, we are programming the bot to respond to the command “!intro”, so if anyone types that in your server while the bot is in it, the bot will respond with a programmed message. In our code, we defined the message as “Hello User! Welcome to the server!” You can change both the prompt message and the response message by redefining them in the code above. Just make sure to maintain the single quotation marks around the messages.

Save this last text file as “bot.js” in your Discord bot folder.

Step 8: Open Your Computer’s “Command Prompt” and Navigate to Your Discord Bot folder

On a Windows PC, you can easily get to the Command Prompt by clicking the Windows icon and typing Command Prompt in the field. Once it’s open, type “cd” followed by the file path to your folder. On our test computer, the command looks like this: “c:UsersDavid’s DesktopDesktopDiscordBot.” That should change the command prompt line to include the file path to your folder. Alternatively, you can navigate to your folder in Windows and hold Shift while right-clicking on a blank area of the folder and choosing Open Command Prompt.

You may also like Download Super Mario Maker 2 for PC Free

Step 9: Use the Command Prompt to Install your bot’s dependencies

Now it’s time to make use of Node.js. In the Command Prompt, with your Discord bot folder in the file path line, type “npm install discord.io Winston –save.” This will automatically install files you need to for your Discord bot into the folder directly.

Also, use the following command line prompt to install additional dependencies: npm install https://github.com/woor/discord.io/tarball/gateway_v6

That should provide you with all the files you need.

Step 10: Run the Bot

Now you are ready to go. To try running your bot, type “node bot.js” in the Command Prompt (make sure you are still navigated to your Discord bot folder). To test your bot’s functionality, get back on your Discord server and try typing in “!intro,” or “!” followed by the prompt message you created in your “bot.js” file. If you coded your bot correctly, sending this command will cause your bot to reply to you with your set message.

Congratulations, you are the proud creator of a Discord bot.

Step 11: Figure out if Your Bot has been made by someone else

The great thing about Discord is the community of shared interests and skills. Users on Discord are always making new tools to improve the service, including bots. Some creators will upload their bots to public databases and allow others to download the bots and use them for their servers. The bots listed in databases can have a variety of functions coded into them, so you will likely be able to find what you need. Before making your bot, do a little exploring on Discord to see if someone else has already made just the bot you need.

You can search Google for databases, as well as specific Discord bots. You can also try looking at Top.gg (formerly Discordbots) or Bots.ondiscord.xyz.

Would you like to read more about Discord Bot-related articles? If so, we invite you to take a look at our other tech topics before you leave!

Subscribe To Our Newsletter

Get updates and learn from the best