Techhurry is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission. Learn more

In this Discord bot tutorial, we will start by discussing the Discord user interface and step by step tutorial on how to make a Discord bot.

Discord is a real-time messaging platform that bills itself as the “universal voice and text chat for gamers” because of its treatment interface, ease of use, and wide range of features, Discord has grown rapidly and is increasingly popular even among those less interested in video games. Between May 2017 and May 2018, its user base has grown from more than twice daily users to more than Slack to more than 130 million to 45 million users.

Read: How to Fix No Route Error on Discord

The requirement of creating a Discord bot

  • Basic Knowledge with JavaScript.
  • Basic knowledge of using your command line (windows) or terminal (Mac/Linux).
  • You must have Node JS installed.
  • You must have Code Editor installed (eg: Atom, Visual Studio Code, Sublime Text).
  • And a Discord Account and Desktop Client.

Time needed: 10 minutes.

How to make a Discord bot

  1. Download & Install Node.js 

    Node.js is a JavaScript runtime that is free and open-source and you will need it to work your bot, eh. Download it at nodejs.org and install it before starting anything else.
    Obviously, you also need a discord account and your own server to test your bot. If you haven’t a Discord account. Then go to DiscordApp.com and create one. If you have it, log in to your account and open the server you want your bot to live on.

  2. Create your bot

    Now you need to create an “app” in Discord for your bot to work. It takes a while to do this, but it’s not too complicated. 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 server.

    First, go to discordapp.com/developers/applications/me. Your account should be logged in, so you’ll go straight to the list of applications for your account. Hit the new app to get started. Give the bot a name, then press the button marked Save Changes.

    Now, in the menu on the right, click Bot. Once in the new menu, click Add Bot under the build-a-bot option. If you only have one app – which we’ve just created – it should appear automatically. Otherwise, select it.

  3. Get your bot’s authorization token

    Look for the token word in the box marked User App Bot: Click to publish. Click on that link and you will publish a string of text. This is the token of your bot’s approval, allowing you to transmit the code.

    Do not share it with anyone – this token allows anyone who has the code to create a code for the bot, meaning anyone who has it can control your bot. If you think the token has been compromised, the good news is that you can easily create a new one with the link below the token that says “Generate a new token”.

    You will need this token in just a second.

  4. Send your bot to your server

    Now scroll to the box detailing the app and look for your Client ID, a long number. Copy the number and add the URL to it, in place of the client word.

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

    The final URL should look like this, but instead of this duplicate with your client ID number:
    https://discordapp.com/oauth2/authorize?&client_id=000000000000000001&scope=bot&permissions=8

    Copy the URL of your client ID number into your browser. This will take you to a website where you can tell Discord where to send your boat. If you open an application or discard in your browser and navigate to your server, you know the channel will say a bot has arrived in the room, and we can see it in the menu at the bottom right of the online member list.

  5. Create a “Bot” folder on your computer

    When you’re doing this, you may want to take a moment to create a folder where you can store all your bot files in a place that is easily accessible on your computer. Call it something simple, like “Discordbot” or “Mybot” so you know exactly what it is.

  6. Open your text editor and make your bot’s files

    You are about to create three files for your bot from your text editor. First, paste this code:

    {
    "Token": "Your Bot Token"
    }


    Replace “Your Boat Token” with the token you created earlier on your bot’s application page. Make sure the token is within quotation marks. Then save the file to the Discard Bot folder you created on your desktop using “auth.json”. Remember to save it as a text file. If Jason has .txt instead, it won’t work.

    Create a new file and enter this code:

    {
    "Name": "greeter-bot",
    "Version": "1.0.0",
    "Description": "My first dispute bot",
    "Main": "bot.js",
    "Author": "your name",
    "Dependency": {}
    }


    If you want, replace the author’s name with your name; If you want something more in harmony with what you are creating, you can change the “description” to something other than “My First Discovered Boat” that will work to make your bot think of what to do.

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

  7. Define your bot’s code

    Another text file needs to be created and it is important that it controls your bot’s behavior. You want to be familiar with JavaScript to have complete control of your bot and know what you are doing, but if you are new to coding and just want to create something, you can copy and paste this code into the file to create a simple bot that will welcome 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.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 responds to specific messages: specifically, anything “!” character. Specifically, we are programming the bot to respond to the command “!intro”, so if someone writes a bot to your server while typing, the bot will respond to the programmed message.

    In our code, we define the message as “Greetings! Welcome to the server!”. You can replace the prompt message and response message in the code above with their new definition. Be sure to put single quotation marks around the messages.

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

  8. Open your computer’s “Terminal/Command Prompt”

    On a Windows PC, you can easily get to the command prompt by clicking the Windows icon and typing “Command Prompt” in the field. When you open it, follow the path of the file to your folder and type “CD”. On my computer, the command can be found: “DesktopDesktopDiscordBot in the CDUUserFile”. This should change the command prompt line to include the path to the file in your folder.

  9. Use the Terminal/Command Prompt to install your bot

    Now, when using Node.js at the command prompt, type “NPM Install Discord. Winston-Save” on your file path line. It will automatically install the file directly to the folder for your Discord bot.

  10. Run the Discord bot

    That should be everything. To try running your bot, type “node bot.js” at the command prompt (make sure you are still navigating to your Discord bot folder).

    Now go back to your Discord server and create the prompt message in your “bot.js” file followed by “! Try checking your bot by typing “Intro,” or “!”. If everything goes well, your bot should immediately return your coded message.

    Congratulations! You just create a Discord bot!

Read more: Best Game Hacker Apps for Android

Now, go back to your server and make sure you stop running bots locally. Is your bot online? Yes? Congratulations, you’ve just created and installed your first Discord bot.

From here, you can learn a lot. Since you can add a bot to multiple servers at once, the servers are part of the Guilds map object. This object contains individual guilds and a channel list of all those guild objects that contain a list of all information and messages. The API is very deep and can take some time to learn, but at least it is easy to set up and start learning.

10 COMMENTS

  1. Hi there! Do you know if they make any plugins to protect against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any recommendations?

  2. A formidable share, I just have given this onto a colleague who was doing a little bit analysis on this. And he actually purchased me breakfast as a result of I discovered it for him.. smile. So let me reword that: Thnx for the deal with! However yeah Thnkx for spending the time to discuss this, I feel strongly about it and love studying more on this topic. If doable, as you develop into experience, would you mind updating your weblog with extra particulars? It’s extremely useful for me. Large thumb up for this weblog publish!

  3. I do not know whether it’s just me or if perhaps everyone else experiencing problems with your site.
    It appears as though some of the written text within your posts are running off the screen. Can somebody else please comment and let me know if this is happening to them as well? This might be a problem with my browser because I’ve had this happen previously. Thank you

  4. Unquestionably consider that that you stated. Your favorite justification appeared
    to be at the internet the easiest thing to have in mind of.

    I say to you, I certainly get irked at the same time as people think about concerns that they just don’t realize about.
    You controlled to hit the nail upon the top as well as defined out the whole thing with no need side effect, other people can take a signal. Will likely be again to get more. Thank you

  5. Howdy! I realize this is kind of off-topic however I needed to ask.
    Does managing a well-established website such as yours take a lot of work?
    I am completely new to operating a blog however I do write in my diary daily. I’d like to start a blog so I can share my experience and feelings online.
    Please let me know if you have any kind of recommendations or tips for new aspiring bloggers. Thank you!

  6. Hi I am Kavin, it’s my first time to commenting anyplace when I read this article I thought me
    could also create comment due to this brilliant article.

LEAVE A REPLY

Please enter your comment!
Please enter your name here