Discord Bots

In recent years there has been a boom in video or voice chat programs. In addition to being able to chat either by video or by voice, many of these programs allow to personalize the chats through automated programs or bots. In this case, we are going to discuss a video and voice chat program very common in the videogame community. It is Discord - a program that allows you to create servers with different rooms where you can talk by voice.

discord bots

In this article, we will show a tutorial on how to create and configure a Discord bot for this chat program. In this case, although there is the possibility of using different programming languages, in this article, we will use the Python programming language.

What is Discord?

Discord is a social platform designed to allow creating chat groups for different games and purposes. You can think of it as something similar to Skype or TeamSpeak, although including the functions of other more professional tools, which has earned the nickname "Slack" of the gamers.

what is discord

This application has versions for both PC and mobile devices, also passing through a client that you can use directly from the browser. It also has many features, allowing chat by text, voice and even makes video conferences, all with a completely free application.

discord mobile platforms

This platform can be used for the purpose you want, of course, but it has had a great impact on the gamer community. All because it is a perfect application to meet friends and colleagues and organize games, and especially because it allows you to talk with other people while you are playing with their voice chat functions.

meet friends in discord

The conversation with other users is done through their servers. This is the name given to each of the communities that you can create in it. To give you an idea, each community is like having your own IRC, since each server can have different channels, among which will be distributed by users to communicate.

discord servers

These groups can be of specific games, but also of studies of developers and other subjects. They can be both public and private, but they are always meeting points in which to meet and chat. The fame of the platform comes from its gamer side, but there are also many other servers dedicated to all kinds of hobbies and interests.

What are Discord Bots?

Discord does not usually come with most of the best community and server management tools. These tools need to be installed as a third party program. These third-party programs are known as BOTs and a list of BOTS acceptable by Discord can be found on our website.

what are discord bots

Apart from the acceptable bots, there are also bots that are not official and cannot be found on the official page but these bots can also do amazing kinds of stuff. There are free bots as well as paid bots and not all bots are compatible with the latest version of Discord.

Best Discord Bots

The best Discord bots you can add to your server:

How to Make Discord Bots?

First, let's see what we will need to be able to create our bot and that is that we will need to register our application in Discord. Obviously, we will need to register in the application and have an account to register this application. Once we have the account, we will register a new application at the following address: https://discordapp.com/developers/applications/

In this direction, we will have to add a new application by filling out the form that appears with the name, description and even an icon for the bot that we are going to make.

add discord bot

Once we have created our application it is necessary to copy the token that we will find in the description screen of our application. In the part of the permits that we will explain later. Of course, let's say that the permissions we can establish are whether our bot is public or private. So that anyone can use it, or we have to add it to a private server.

discord bot token

We will see a link that we will press to obtain the necessary token to connect with the bot. This chain will be saved and of course, it will be secret (do not upload to a public repository such as Github, etc ...). After saving this token, we will move on to the programming of our bot.

First of all, we will need to have Python 3.4 or higher installed. From our experience, we recommend installing Anaconda to have better management of environments.

python library discord.py

After having prepared our python environment, we will see what library we are going to use to connect to Discord. This library is called discord.py and allows you to create bots in a simple way to connect to Discord either by text chat or as voice chat and can send audio to these voice channels. To install this library we will use pip to install it.

$ pip install discord.py

In the previous case, only the connection and text chat libraries will be installed. If by some chance we needed the necessary libraries to use voice chat we will add the option «voice». It will also be necessary to install the OpusLib library in our operating system.

With the libraries already installed, we will create our bot with the following code:

import discord

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')

client.run('your token here')

As we see in the previous code, we will need the token that we have previously registered, which we will put in the corresponding variable. We strongly recommend that the token is not added to a Git repository or published. The previous code, we see that when a message is received that starts with "Hello!" the bot will respond by greeting the user.

Before you can run the bot, you will need to add it to the server and that leads to our next topic.

Initialization And Configuration Using Javascript

make discord bot with javascript

Before I started I wanted to make a point about the choice of technology and the library:

Start a new project and install Discord.js using NPM:

$ npm install --save discord.js

Then create a file bot.js and put this in:

const Discord = require("discord.js");
const client = new Discord.Client();

client.on('ready', () => {
    console.log('Logged in as ${client.user.tag}!');
});

client.on('message', msg => {
    if (msg.content === 'ping') {
        msg.reply('Pong!');
    }
});

client.login('token');

Replace token with the one in your application, and run the command:


$ node bot.js

Before you can run the bot, you will need to add it to the server and that leads to our next topic.

How to Add Bots to Your Discord Server?

Adding bots to your Discord is a very easy process and it can be done within few minutes. Before you can add bots to the server you will need admin access to the server called manage server. Installing bots vary, while some will require you to be logged in to server others won't. Here are the steps to follow:

  1. Go to the official Discord site and log in.
  2. Go to your profile and check under General Permissions. Ensure that Manage Server is enabled.
  3. Click on Add Bot to Server or Invite Bot. This depends on the source of your bot.
  4. Choose the server you would like to add the bot to and accept in the popup window that will appear afterwards.
  5. Open your server and you should see your bot on the sidebar.

That is all you are done adding the bot to your server. There is another method but it is for experienced users. This is known as the URL method. It is the best way to add GitHub bots. Follow the next steps:

  1. Just like the previous method, you need to log in to your server.
  2. Go to https://discordapp.com/oauth2/authorize?client_id=BOT_CLIENT_ID&scope=bot&permissions=0. (Note: You need the Client ID of the bot for this to work. You need to change BOT_CLIENT_ID in the URL to the original Client ID of the bot).

Done! That's all you need to add bots to your Discord Server. Sometimes you may need to authorize the bot before it starts functioning properly.