Create & Deploy a Discord Bot (Part 1/3 - Bot Creation)

May 23, 2022 by Zacharia Mansouri | 3306 views

Python Bot Deployment

https://cylab.be/blog/216/create-deploy-a-discord-bot-part-13-bot-creation

There are times when you need to manage a community. Mailing lists are still in use nowadays but there exists other modern ways like creating a Discord server to chat with a bot that can fulfill many tasks for you and your community!

part1.jpg

In this blog post you will learn how to create a bot application using the Discord interface. This blog post is the first of a series of three. The two next blog posts will cover the following subjects:

  • Adding features to the bot using discord.py
  • Deploying the bot on the cloud using Heroku

Creating a discord bot requires many steps that will be illustrated hereunder. It is assumed that you already possess a Discord account. Otherwise, here is the register link. It is only after successfully completing all the below steps that we will dive into the Python code needed to add features to the bot in the next post.

Here are the 3 steps we’ll first go through:

  • Create a server
  • Create a bot application
  • Link the bot to the server

I personally used Discord’s web interface but you can also use the Discord app client. The steps are the same, only the visuals might change a little.

Create a server

Open Discord. You should see something like the following screen:

cs1.png

You can add a server by clicking the top left icon in green:

cs2.png

It opens the following options. Choose to create your own server:

cs3.png

Here we choose to create a simple server for us and our friends but you could also do it for a club or a community:

cs4.png

Then you can name and add an image to your server. The server is named EventServer. Click on Create to complete the server creation:

cs5.png

Your new server created, it contains two channels, a text channel called general and a voice channel called General:

cs6.png

You can add a new channel by clicking on the little + sign next to the text channels list:

cs7.png

It opens the following channel creation window:

cs8.png

Name that new channel admins and click on Create Channel to complete its creation:

cs9.png

Repeat the channel creation process to add a second channel called events.

You should now have a server with three text channels called: general, admins and events.

Create a bot application

This step will require you to connect to the Discord Developer Portal that proposes you to add a new application. That is a Discord application that we will later configure in order to make Discord recognize it as a bot. To start this bot creation process you must click on New Application:

cb1.png

It should open the following window that asks you to name your application:

cb2.png

Do not use the word discord in the name of the application. If you do so, you will fail to convert your application to a bot application later. In fact, Discord does not want people to create bots containing the word discord in their names. Here the application is called CylabBot. Click Create to complete the creation of the application:

cb3.png

The application is now created. You can add an icon to it, complete its description, etc. Here we do not need to customize it so we’ll click on the Bot tab on the left to tell Discord that it must consider this CylabBot application as a bot:

cb4.png

Click on Add Bot:

cb5.png

And confirm:

cb6.png

The application can now be used as a bot. You will make use of that bot application with a token that is needed to connect to the bot. That token can be seen by clicking on Reset Token:

cb7.png

Confirm the reset of the token:

cb8.png

Copy the token that appears (I hid it by a red rectangle, it must be kept secret for obvious reasons) and paste it somewhere to retrieve it later. You’ll need it for Part 2 when you’ll run a Python script that can connect and add features to that bot:

cb9.png

You now possess a Discord server and a custom Discord bot. The next step is to link that bot to the server and give it the permissions needed for the features we’ll add to the bot.

In this last step, you will add your freshly created bot to your server. First click on the OAuth2 tab in the left panel:

lbs0.png

Two new sub-tabs should appear: General and URL Generator. Since we’ll generate an url that will add the bot to the server, click on URL Generator:

lbs1.png

Select the scope of the URL as a bot scope:

lbs2.png

A list of bot permissions should appear. These are all the actions your bot will be granted to achieve on the servers you’ll link it to. Keep in mind that it’s better to only give necessary permissions, imagine what could happen if Discord vulnerabilities are exploited and your bot gets hacked!

lbs3.png

For this blog post, let’s give the bot 6 text permissions: Send Messages, Manage messages, Embed Links, Read Message History, Mention Everyone, Add Reactions:

lbs4.png

You can now copy the generated URL that is under the list of the bot permissions:

lbs5.png

And paste it in your browser, where the following page should appear:

lbs6.png

Select your new EventServer from the list that contains all your servers:

lbs7.png

Click on Continue to continue the process:

lbs8.png

From the list of bot permissions you gave to the bot, you can decide which ones you want to apply to the server you just selected. Here keep them all selected and click on Authorise:

lbs9.png

You might need to resolve a captcha:

lbs10.png

The bot has been added to the server! Discord tells you so with the following web page:

lbs11.png

You should also receive a Discord notification in the general channel of your EventServer server, in fact, the CylabBot has now been added to your server with the 6 permissions you gave it:

lbs12.png

That was already quite long wasn’t it? Don’t hesitate to take a break… The next blog post about Creating & Deploying a Discord Bot will teach you how to add features to the bot using a Python script based on discord.py.

This blog post is licensed under CC BY-SA 4.0

This website uses cookies. More information about the use of cookies is available in the cookies policy.
Accept