Throughout several past years, Discord has proven itself to be one of the most convenient and quite possibly most entertaining platforms for instant messaging out there. Now, there is a plethora of reasons for this, but one that everyone would agree with is the existence of Discord bots.
Bots on Discord can be used for many reasons, from the simple ones, like automating certain features in your group chat, to playing music for all the members, including many others. But how do you actually get one? You can of course download some that are already premade, but get your wallet ready if you want to unlock all of their features, or you can simply try to make one of your own. And even though it sounds like something only a programmer could do, if you follow the steps bellow, it really is not.
Read More: How to install emulators on PS Vita
Table of Contents
Steps to program Discord Bot
First of all, you need to equip yourself with some tools. In this case, that means downloading and installing an open-source JavaScript runtime called Node.js which you will use to make your bot function, as well as opening up a Discord account, if you do not have one, and setting up a server where you will actually test if everything works as it should. A text editor program is also necessary for all the coding required, Notepad++ being what most people usually go with.
With all of that prepared, it is time to get the “authorization token” for the bot from Discord, so your code can get recognized as a bot and added to the servers. If you are logged in, go straight to this link.
Next, click New Application, name your bot and click on Save Changes. Following this, on the right-hand side, in the menu, click the option Bot. Under the Build-a-bot, click the Add Bot button. The application previously created should appear automatically.
The next step is to find the box App Bot User and look for a string of words Token: Click to Reveal. This is the official authorization for your bot, which allows you to send it code that will be recognized by Discord.
After this, you should scroll up to App Details and locate a long number, which is your Client ID. When you successfully find it, just add it to this URL
instead of the CLIENTID part. With that done, copy the URL into your browser and it should lead you to a website where you can actually guide Discord where to place your bot. It is also advisable to create an easy-to-find folder on your computer for storing your bot’s files, because you need simple access to them.
Now is the time for the main thing. You are going to create three distinct files using the text editor and save them as .json files, since the typical .txt files are not actually used in this situation. The first one contains your token and is represented like this:
{
“token”: “Your Bot Token”
}
The only difference is that you will actually use the already generated bot token instead of the “Your Bot Token” line, but keeping the quotations. Save the first file in the folder mentioned above.
The next file that you need to create contains this code:
{
“name”: “greeter-bot”,
“version”: “1.0.0”,
“description”: “My First Discord Bot”,
“main”: “bot.js”,
“author”: “Your Name”,
“dependencies”: {}
}
You can make some changes here, such as changing the author name or description, which does not change the actual functionality of the code itself, just makes the bot more personal and fit to your liking. This file should be saved under the name “package.json” and placed into your Discord bot folder, alongside the first one.
The final text file to be made, controls how your bot behaves. If you are new to coding and have little to no JavaScript proficiency, just copy and paste the following chunk of code, in order to create something just for a start:
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;
}
}
});
This file should be saved as “bot.js” and complete the trio of files that construct your very own Discord bot.
With all of that done, there is not much work left. Open the Command Prompt by holding the Windows and R buttons on your keyboard together, which will open the “Run” box, and then typing cmd and pressing enter. Once you have opened it, simply type cd and add the file path that leads to your folder.
With your folder path line in the Command Prompt, type:
npm install discord.io Winston –save.
which automatically installs files necessary for your Discord bot in the folder specified. Additionally typing the following line:
should provide you with everything necessary to actually run the bot, which is the next step.
In order to do this, type node bot.js in the Command Prompt and navigate to your Discord server. Typing a simple “!” should make the bot react with a prompt message provided in the code. If this step works with no issues, then you can proudly say that you own a Discord bot you made yourself.
For better understanding, you can watch this short YouTube Video and learn the basics of programming your own Discord bot.
Read More: How many acts are in Diablo 3
All in all, these steps should be taken as the basis for what can be done with Discord bots. Researching other people’s works, investing some time into improving your JavaScript skills or simply asking for help online can go a long way, but one thing is certain – you are the owner of simple, but perfectly functional Discord bot.