Discord is a popular chatting program that’s highly used and favored by gamers. Users can create their own Discord channels for free and invite people to join them. Some people use Bots in Discord to keep music playing, greet new people in the channel, and so much more. This wikiHow will show you how to create a bot for Discord. You'll need to be at least a little familiar with coding since Javascript is what makes the bot work.

Part 1
Part 1 of 6:

Preparing Your Computer

  1. 1
    Download Node.js from https://nodejs.org/en/download/. Node.js is a free JavaScript runtime that you’ll need to make your bot. You can pick either the Windows or macOS installer as well as which version. The LTS version is recommended for this process.
  2. 2
    Run the installer. A Windows computer just needs to click on the downloaded file to launch the installer, but a macOS computer needs to unpack the file to find the installer application. Make sure you read any and all agreements as you go through the installer.
    Advertisement
  3. 3
    Create a Discord account (optional). If you don’t already have a Discord account, you sign up for one at https://discord.com/.
  4. 4
    Login to your Discord account and channel. Open the Discord app on your computer and navigate to the channel you want your bot in.
  5. Advertisement
Part 2
Part 2 of 6:

Creating the Bot on Discord

  1. 1
    Go to https://discord.com/developers/applications/me in a web browser. You should be logged in already through the app, but log in again if you are prompted. In this part, you'll be creating an app that activates the bot, so you'll be creating an app as well as a bot.
  2. 2
    Click the blue New Application button. You’ll see this to the right side of the browser. A window will pop up for your app’s name.
    • Type in the application's name and click “Create.” You'll want to create a name that is descriptive, like "Greeterbot" if your app bot greets people. However, "Greeterbot" will most likely trigger errors later on because it's a popular name, so add a series of numbers after the name, like "Greeterbot38764165441."
  3. 3
    Click Bot in the left-hand menu. This is also the jigsaw puzzle piece icon.
  4. 4
    Click Add Bot. This is under the “Build-A-Bot” header.
    • Click “Yes, do it!” in the pop-up to confirm your action.
    • If you get an error about the name being too popular, go to the application page and change the app name. For example, “Music Bot” was too popular, so adding a few numbers to the end of the app helped.
  5. 5
    Click Click to Reveal Token. You’ll see this in the information area of your bot. When you click that text, you see a string of letters and numbers.
    • Click “Copy” to copy all that text. You can paste it on a sticky note somewhere, but make sure you have access to that code and don’t give it out to anyone. Whoever has that code can control the bot. This code will always be here if you need it.
  6. Advertisement
Part 3
Part 3 of 6:

Sending the Bot to the Discord Server/Channel

  1. 1
    Click General Information. This is in the menu on the left.
  2. 2
    Click Copy under Client ID. You'll see this around the middle of the web page.
  3. 3
    Paste your copied ClientID into the following URL:https://discord.com/oauth2/authorize?&client_id=CLIENTID&scope=bot&permissions=8”
  4. 4
    Paste your URL into the address bar on your web browser. You’ll be taken to a page where you can assign your bot to a channel.
    • Click the drop-down box to display all your compatible channels.
    • Click “Authorize” to continue. You’ll get a confirmation that the bot was moved and that you can close the active tab.
  5. Advertisement
Part 4
Part 4 of 6:

Coding the Bot

  1. 1
    Create a folder on your desktop for your bot code. You’ll be making files of code that will go in here.
  2. 2
    Open a text editor. You can use the default programs like Notepad for Windows or TextEdit for Mac.
  3. 3
    Type the following code:
      {
      “token”: “Your Bot Token”
      }
      
    • Make sure you enter that Bot Token number you got from the previous steps between the quotation marks in the text.
  4. 4
    Save the file as “auth.json”. Make sure the file doesn’t save with a .txt file extension.
  5. 5
    Start a new document. You can do this by either pressing Ctrl+N (Windows), or Cmd+N (Mac), or clicking “New” from the “File” tab.
  6. 6
    Type the following code:
      {
      “name”: “greeter-bot”,
      “version”: “1.0.0,
      “description”: “My First Discord Bot”,
      “main”: “bot.js”,
      “author”: “Your Name”,
      “dependencies”: {}
      }
      
    • Make sure you replace "author” name with your name. You can also change the “description” if you don’t like “My first discord bot.”
  7. 7
    Save the file as “package.json”. Make sure the file doesn’t save with a .txt file extension.
  8. 8
    Start a new document. You can do this by either pressing Ctrl+N (Windows), or Cmd+N (Mac), or clicking “New” from the “File” tab.
  9. 9
    Type your bot’s code. For example, if you want to create a bot that responds to any messages that start with "!", type the following 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.
               }
           }
      });
      
  10. 10
    Save the file as “bot.js”. Make sure the file doesn’t save with a .txt file extension.
    • You can close your text editor.
  11. Advertisement
Part 5
Part 5 of 6:

Installing Bot Dependencies

  1. 1
    Open a command prompt window. On Windows, you can search “Cmd” in the Windows search field in the Start Menu. On Mac, you can search Spotlight for “Command Prompt.”
  2. 2
    Navigate to your bot folder on your desktop. For example, you can type cd\Users\Default Desktop\Desktop\DiscordBotfoldername.
  3. 3
    Type npm install discord.io winston –save and press Enter. With Node.js installed, this line will automatically download the dependencies for your bot in your desktop folder.
  4. 4
    Type npm install https://github.com/woor/discord.io/tarball/gateway_v6 and press Enter. That code will make sure there’s nothing else you need to install for your bot to work.
    • You now have code for your bot and will test that your code works in the next part.
  5. Advertisement
Part 6
Part 6 of 6:

Running the Bot

  1. 1
    Type node bot.js and press Enter in the command prompt. If you get an error line, you did something wrong.
  2. 2
    Type “!Intro” in Discord. You’ll want to type this in the channel your bot is in. The example code provided triggers the bot to respond "Pong!" to text starting with “!”. So to test if the bot is working, type “!Intro” and wait for a response.[1]
  3. 3
    Check your coding if you didn't hear a response. If your bot didn't respond to your "!Intro" in Discord, go through this wikiHow again and check to make sure your bot is set up correctly. Make sure:
    • Node.js installed correctly.
    • The Bot Token is entered correctly in your auth.json file.
    • You’re in the same channel as the bot.
    • The bot is on the server.
    • Your coding is correct in your auth.json, bot.js, and package.json files.
    • You downloaded all the dependencies for your bot to work using Command Prompt with Node.js installed.
  4. Advertisement

Community Q&A

  • Question
    My bot says it's offline what do I need to do?
    Josh I Guess
    Josh I Guess
    Community Answer
    Have you done the code correctly? Try redoing the code. Make sure you do "node bot.js" without the quotes when you finish the code.
  • Question
    What do I do if it says error when typing node bot.js into command prompt?
    Josh I Guess
    Josh I Guess
    Community Answer
    Have you done the code correctly? Try redoing the code. Make sure you're typing everything right.
Advertisement

About This Article

Darlene Antonelli, MA
Written by:
wikiHow Technology Writer
This article was co-authored by wikiHow staff writer, Darlene Antonelli, MA. Darlene Antonelli is a Technology Writer and Editor for wikiHow. Darlene has experience teaching college courses, writing technology-related articles, and working hands-on in the technology field. She earned an MA in Writing from Rowan University in 2012 and wrote her thesis on online communities and the personalities curated in such communities. This article has been viewed 82,818 times.
How helpful is this?
Co-authors: 12
Updated: July 29, 2022
Views: 82,818
Categories: Discord
Article SummaryX

1. Download and install Node.js.
2. Open the Discord app and log in.
3. Create the bot on Discord.
4. Put the bot in a Discord channel.
5. Code the bot.
6. Install bot dependincies.
7. Test the bot works.

Did this summary help you?
Advertisement