DeasileX

How To Make A Discord Bot Using Python And Discord API?

How To Make A Discord Bot

Discord is a lot more than just a social media app. Sometimes managing the application alone can be a tough job. It has got text, video, and audio servers all working at the same time. For the user’s ease Discord has introduced the concept of Bots. Well, here is an article that will tell you how to make a Discord bot with Discord API Python.

Bots are the AI (Artificial Intelligence) that help the user to manage the tasks going around in its discord account. There are various predefined bots in the Discord applications such as the Moderation bots, translation bots, music bots, and many more. Other than this discord provides an opportunity for the programmers to create their discord bot. Here we are with an article that will guide you on how to make a Discord bot with Discord API Python.

Well, if you are looking for how to make a Discord bot, then the first thing you need to do is to make a Discord Bot account. After you have created the bot account, you have to invite the bot to the server via the invite URL. After you are done with this process, you need to write the Python code in the Discord API wrapper.

This guide on “How To Make Discord Bot” will explain to you every process mentioned above. 

How To Make A Discord Bot?

Further in the article, you will find the step to step guide on “How to make Discord bot”. We have mentioned the simplest method for the purpose and specialty of the article is that you don’t have to download the special Python IDE for creating the bot.

How To Make A Discord Bot Account?

How To Make A Discord bot Account

Before you start making your Discord bot you must have a Bot account on the platform. After you have created a Discord bot account, you can start working with the Discord API (Application Programming Interface) and Python Library.

Follow the steps given below to create a Discord bot account.

Step 1: The first step would be to log in to the Discord Website.

Step 2: Next, Navigate to the “Application Page” and click on the “New Application” button.

Step 3: Now, the next page will ask you to create the application name. Name the application and click on “Create”.

Step 4: On the new desktop window, on the left window pane navigate for the option “Bot”. Click on it.

Step 5: And, then Add Bot On the right side of the window. 

Step 6: Confirm the action by clicking on “Yes, Do it”.

Step 7: Make sure that the check box against the Public Bot is marked and the check box against the Require OAuth2 Code Grant is Unmarked.

Step 8: Your Bot has been created.

Step 9: On the next screen, you will find an option to copy the token. This is the password to your bot account. 

Note: Do not share this password with anyone. If someone has access to your Bot account, then your discord account can be controlled by them.

You can regenerate your Discord bot password anytime.

Inviting The Bot To Join The Server?

How To Make A Discord bot - Inviting The Bot To Join The Server

After you have created the Bot now you have to invite the bot to join the server. We will do it by creating an invite URL. Follow the steps given below for the purpose.

Step 1: Go to “OAuth2” and click on it.

Step 2: Now navigate to the “Bot” under the scopes section.

Step 3: Next, you need to select the permissions that you want your Bot to do. Be careful while assigning the permissions to the bot, especially the Administrator permissions.

Step 4: After that click on the “Copy” button that carries the URL on the top.

Step 5: Now, this is the URL we are going to use to invite the bot to join the server. 

Step 6: Paste this URL in your browser and choose the server you wish to invite the bot to.

Step 7: Click on “Authorize”

Note: You need to have the Manage Server Permissions to add the bot.

How To Make Discord Bot By Coding In Discord.Py Library?

Now that we have created the bot, we will be writing the code in the discord.py python. Discord.py is an API wrapper for Discord and it will be helping us in writing the Discord Bot code in Python.

How To Make Discord Bot Using Repl And Discod.Py?

How To Make Discord Bot Using Repl And Discod

You can use any python editor on your personal computer to write the python code for the bot. But, the best suggestion would be using the Repl. Repl is an online IDE that can be used directly on the browser to write the python codes for the Discord Bot.

To write the discord bot in the Repl. start by visiting the Repl Website. Create the new Repl and Select the language as python. Now you can write the codes for the Discord bots which are called the events.

How To Make Discord Bot That Responds To Events?

The whole discord python bots revolve around the concept of events. Events are the things or queries that you listen to and then respond to. For example, you make a bot for the chat server and program it in the way that if it reads “hello” it will reply with “Hello, How are you?”. In the above event, reading “Hello” and responding is called a whole event.

Here is the discord.py code that will work in the order mentioned above.

import discord

import os

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, How are you’)

client.run(os.getenv(‘TOKEN’))

Conclusion

Well, that was all about how to make a Discord bot. If you are still facing trouble or have any queries regarding the article above. Don’t hesitate to ask us. Python is a powerful language and we can create a lot more than the text bots. So, if you want us to write more discord.py codes for different events then do write to us in the comments section.

Frequently Asked Questions

Q. Is Discord.py Easy?

Now that we have created the bot, we will be writing the code in the discord.py python. Discord.py is an API wrapper for Discord and it will be helping us in writing the Discord Bot code in Python.

Q. How Do You Make A Discord Bot In Python 2023?

Navigate to discord.com/developers/applications and log in.

  1. Click on New Application.
  2. Enter the application’s name.
  3. Click on Bot on the left side settings menu.
  4. Click Add Bot and confirm with Yes, do it.

Q. Can I Code A Bot With Python?

Either Python 2 or 3 can be used with the code which is also available on GitHub. Dropbox open sourced their security Slack bot, which is built in Python.

Leave a Comment

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

Scroll to Top