Categories
How to

HOW TO MAKE DISCORD BOT

HOW TO MAKE DISCORD BOT

With the current level of popularity discord is at, specifically among gamers and developers, it’s obvious that it is one of the most searched about apps. It is popular because it’s free, it’s social and it’s amazing.

Many things can be done on discord but what especially mention worthy is, you can make your own bots on discord! Trying to understand what bots do? They make discord an interactive platform. Like, you must have encountered one of those that play music for users or greet and elevate your rank. Yes, that’s bot.

It’s not rocket science to make one of your own. So without further ado, let’s go on to how to make a discord bot.

Setting up a Discord account

Firstly, download Node.js in JavaScript. It’s free and open source. It would be the first thing needed to make the bot work. So, download it and then install it before we get anywhere else. Of Course a Discord account would be needed and your own server where we would be testing the bot. Go to Discordapp.com and create your account. Also, have a text editor like Windows where we will do the coding.

The bot creation

A part in the creation of the bot requires the Discord to recognize your code and adds your bot to the ones on its server. So, we’ll need to create an app on Discord to make it work. Sounds complex but it’s not.

Go on to discordapp.com/developers/application/me

Log in to your account and head on to new application. Name your bot and save the changes. Now, go to the option Bot, click build a bot and go to Add Bot. Select the application we have just made.

Getting the authorization token

You would find a box App Bot User and words ‘Token:Click to reveal’ under it. This link would give a string of data. That is our required authorisation code. Share it at your own risk. This is the code that gives one control over the bot. In case you shared it with someone you regret or someone got it without your will, there is an option of ”Generate the new token” for you.

Sending the Bot to your server

We’ll start with finding the Client ID. Scroll up to App details and find the Client ID. Copy the number and paste it in this link in the place of CLIENTID –

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

Open this URL in your browser. It will take you to a website where you will tell the Discord where your bot is to be sent. To check if it worked, open Discord in an app and navigate to your server. Channel will show that a bot has joined the room and your bot will be visible under the online members list.

Bot folder

You know how to make a folder on your computer. Make a folder and store all your Bot files in it.

Making files for your bot

We’ll make 3 files for your bot. Let’s make the first. Paste this code in your text editor –

{
“token”: “Add the token you generated”
}

Don’t write the words add the token you generated. You must’ve understood which token to add over here. Yes, the one we generated earlier. Add it under the quotation mark only. Save this file under the name of ”authorisation.json” in the discord bot folder we created earlier. We are compiling things neatly and in a handy way.

Make another file with this code –

{
“name”: “The Bot”,
“version”: “1.0.0”,
“description”: “My Own Discord Bot”,
“main”: “bot.js”,
“author”: “Your Name”,
“dependencies”: {}
}
You can change the description according to your choice. Also, you can name the bot to your name. Save this file with the name of pack.json in the same Discord bot folder.

The Bots code

Now we will define a code for your bot. This is the third file. If you are new to programming and not well versed in Java, you can just copy and paste this code into your text editor. This bot will greet the servers as they come into the lobby. We are designing the bot to respond at an exclamation mark. If someone types ‘!intro’ while the bot is in the server, it will respond with the message “Welcome to the server!”. Here is the code –

var Discord = require(‘discord.io’);
var logger = require(‘winston’);
var auth = require(‘./authorisation.json’);
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
colorize: true
});
logger.level = ‘debug’;
// Initializing Discord Bot
var bot = new Discord.Client({
token: authorisation.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) {
// This is how bot will know to execute the command
// It will take the messages that 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;
     }
 }

});

Save this file with the name of bot.js.

Opening the files in command prompt

Go to the windows icon and open a command prompt. You will simply find it by entering command prompt in the search bar. In command prompt, type cd and then your folder’s location, like: cdDocumentsDiscordBot.

Installing the files bot needs

Now, we will install files in your discord bot folder that your bot needs. Type “npm install discord.io Winston -save.” The files that the bot needs would be automatically installed in the folder. Also use the following command line:

https://github.com/woor/discord.io/tarball/gateway_v6

Now you have all the files that you need.

Running the Bot

For running the bot, make sure your discord folder is navigated to in your command prompt. Now type “node bot.js”.

Okay, now, in your Discord server, test your bot by typing ‘!intro’ or anything after the exclamation mark. Your bot should display the message you programmed it to.

Celebrations! You made your own discord bot.

Finding out if the bot you need already exists

If you’re just learning to make a bot, well go on. But if you are making the bot because you need one and you have no idea if anyone has done the job for you, we can help you. Discord is a wide platform and many people make bots on it, even open ones. You can go on and download and use them and save yourself some time. You can search for the bots on discordbots.org and bots.discord.pw. Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *