Make Discord Bot using Python

Make Discord Bot using Python

By M.Muzammil | February 02, 2023

Make Discord Bot using Python

Here's a tutorial on how to build an auto-reply bot for Discord using Python.

First, ensure you have Python 3 and pip installed on your computer. If you don't have them installed, you can download Python 3 from the official Python website ( and install it.

Next, install the library using pip:

pip install

After installing the library, create a new file called and add the following code to it:

import discord

client = discord.Client()

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

async def on_message(message):
    if == client.user:

    if message.content.startswith('$hello'):

In the code above, we first imported the discord library and created a new Client object. Then, we defined an event that will be called when the bot is ready (i.e., logged in to Discord).

Next, we defined an event that will be called whenever a message is sent to a server the bot is a member of. In this event, we check if the message was sent by the bot itself (to prevent the bot from responding to its own notices) and if the message starts with the $hello command. If both of these conditions are true, the bot will send a message saying "Hello!" to the same channel that the message was sent in.

To run the bot, replace YOUR_BOT_TOKEN_HERE with the bot token that you obtained earlier. Then, run the following command:


If everything was set up correctly, your bot should now be online and responding to the $hello command. You can add more commands and functionality to the bot by defining additional events and using the Discord API.

I hope this helps! Let me know if you have any questions.

Tags :

Related Posts


I am Muzammil, a Self-taught Web Designer & Developer. I haven't yet completed my college degree. Started learning programming at the age of 12 and still learning. I love to work in Javascript and make eye-catchy designs. Free for your calls :)

Be The First To Comment