Skip to main content

How to make a Discord bot

Over the last five or so years, Discord has consistently shown that it is the instant messaging platform for not only gamers but anyone looking to message, video chat, or stream with friends online. Among the reasons why are Discord bots. Bots can help you do everything from automate mundane tasks to start playing music across your server, and in this tutorial, we’re going to show you how to make a Discord bot.

Difficulty

Moderate

Duration

30 minutes

What You Need

  • Discord Account

Although automation is the main reason to use a Discord bot, you can really program one to do anything (anything that you can cram in some JavaScript code, at least). You don’t need any programming knowledge to get started, either. Our guide will get you started making your own Discord bots, even if you’ve never touched a line of code before.

How to make a Discord Bot

Step 1: Download Node.js and set up a Discord account.

Node.js is a JavaScript runtime that’s free and open source, and you’ll need it to actually make your bot work. Download it at nodejs.org and install it before you get started on anything else.

Obviously, you’ll also need a Discord account and your own server to use to test your bot. If you haven’t created one yet, go to Discord.com and create one. If you do have one, log in to your account and open up the server in which you want your bot to live.

You’ll also need a text editor program, like Notepad++ on Windows, to code with.

Step 2: Now you’ll need to create an application on Discord to make your bot work. This takes a little doing, but it’s not too complex. 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, head to discordapp.com/developers/applications/me. Your account should be logged in, so you’ll go straight to your account’s list of applications. Hit 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 — it should appear automatically. Otherwise, select it.

how to make a discord bot my apps

Step 3: In the box marked App Bot User, look for the words Token: Click to Reveal. Click that link and you’ll reveal a string of text. That’s your bot’s authorization token, which allows you to send it code. Don’t share it with anyone — that 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. Mark down your token. You’ll need it in just a second.

how to make a discord bot box

Step 4: 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 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=000000000000000001&scope=bot&permissions=8

Copy the URL with your client ID number in it into your browser. That’ll take you to a website where you can tell Discord where to send your bot. You’ll 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’ll see it on the right side menu under the list of online members.

how to make a discord bot connect

Step 5: While you’re 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. Call it something simple, like “DiscordBot” or “MyBot,” so you know exactly what it is.

how to make a discord bot folder

Step 6: You’re going 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.

how to make a discord bot package code

Step 7: There’s one more text file to make, and this is the important one that controls your bot’s behavior. You’ll want to be familiar with JavaScript to really have full control of your bot and know what you’re doing, but if you’re 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.

(Thanks to Medium user Renemari Padillo, whose bot tutorial helped us create this one. Check out his tutorial for code troubleshooting and other advice.)

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’re 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, “Greetings! 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.

how to make a discord bot botjs

Step 8: 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:UsersPhil’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, then choose Open Command Prompt.

how to make a discord bot command prompt

Step 9: 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.

how to make a discord bot command prompt node js

Step 10: Now you’re ready to go. To try running your bot, type “node bot.js” in the Command Prompt (make sure you’re 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.

how to make a discord bot test

The great thing about Discord is the community of shared interest and skill. 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’ll 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.

Editors' Recommendations

Steven Petite
Former Digital Trends Contributor
Steven is a writer from Northeast Ohio currently based in Louisiana. He writes about video games and books, and consumes…
All Resident Evil 4 remake Wayshrines and how to open them
An open wayshrine with a bracelet inside.

In the opening chapters of the Resident Evil 4 remake, you will come across strange shrines erected by a cult. These can be interacted with, but prompt you to use an item. Unfortunately, you won't even have the chance to open the first couple you find since the item required to open them can't be picked up until a bit later -- and only if you know where to search for it. But it's ro say that the treasures you get from them make it worth your time to backtrack and grab all the goodies inside. Here's how you can open all the Wayshrines in the Resident Evil 4 remake, and what each one holds inside.
How to get the Wayshrine Key

Surprise surprise, but Wayshrines can only be opened once you grab the Wayshrine Key. It will feel like a long time, but you can't even access the key until you reach Chapter 4 and beat Del Lago. Once you can explore the lake, head south to the Mural Cave. Deep in the caves, you will find an ornate cabinet after solving the puzzle in the cave. You can get there by going down the path from the southern dock and through the section with the two large stone hands. Thankfully, unlike Small Keys, the Wayshrine Key is reusable and can open every Wayshrine in the game.
How to 0pen Wayshrines

Read more
How to solve the Castle Sword puzzle in Resident Evil 4 remake
Leon looking at murals of a knight.

The castle section of the Resident Evil 4 remake is one of the most diabolical. Aside from being visually distinct from the previous village area, this location is full of tougher enemies and deadlier traps. Once you've managed to escape from the dungeons and up into the castle proper, you will be blocked by a gate beside some images of a knight in different situations. Something is off about all of them, and one part missing entirely. This is the sword puzzle, but it isn't as straightforward as you might assume looking at it. Here's how to solve the Sword Puzzle and make your way into the Audience Chamber in Resident Evil 4.
How to solve the Castle Sword puzzle

The first thing you'll notice about this puzzle is that there are four murals of the knight, but only three swords to pick up in this room. The last sword is behind another locked gate, but this one you can open. The gate has three animals on it, an eagle, deer, and snake, which correspond to three different plates. As each one is activated, the symbols on the gate will light up to show you're on the right track. The deer can be activated by pulling the chain beside the gate, while the second two are on the other side of the gate to the right and need to be shot.

Read more
Resident Evil 4 lock codes: how to solve the Village Chief’s Manor combination lock puzzles
Leon Kennedy walking in the Resident Evil 4 remake.

In the world of Resident Evil 4, it isn't just the existence of viruses and parasites that turn normal people into crazed zombies that differentiates it from our own reality. In this ream, most homes and buildings don't just simply lock their doors, but secure them using obscure puzzles, such as the one you will find early on when you reach the Village Chief's Manor. This small home has two major roadblocks preventing you from moving on and pursuing your goal of finding the president's daughter. While there is a clue to the first puzzle, it is still somewhat cryptic and easy to miss, while the second is much less clear on what you're even being asked to do. Don't let these early puzzles stump you for too long -- use our help in solving the Village Chief's Manor puzzles in Resident Evil 4.
How to solve the cabinet lock puzzle

After entering the manor and dealing with a lone enemy in the bathroom, the first puzzle you need to solve is on the ground floor. Around the back of the house, down the hall with a Red Herb, is a large cabinet. The lock has three symbols you need to correctly align to open, and those symbols include things such as wheat, animals, babies, and birds. You won't be able to guess this one, so instead, you need to go up to the second floor and examine a book on a table in the hallway. This document, called "Illuminados 4:3, spells out the solution. The important part is the middle paragraph with the highlighted text that reads: "The old farmer, his finest crop./ The Slight swineherd, his stoutest pig./ The beggarly grandam, her own beloved babe."

Read more