How to make your own discord bot in under 15 minutes (With Python)

Lopamudra Das
DataX Journal
Published in
6 min readMar 31, 2023

Python is known for its simplicity and versatile nature, which is why so many companies prefer using it. For a beginner (much like myself), Python is probably the fastest language to learn out there. So this is for all of you trying to delve into the world of coding, totally beginner-friendly.

Installing Python

As this is a beginner-level program, we’ll resort to using PyCharm.

STEP 1: First things first, we start with downloading the latest python version from Python.org (the latest version as of now is 3.11.2).

STEP 2: After installing python on your computer, we get to downloading PyCharm. Just Google “Download PyCharm” and click on the very first link.

STEP 3: Download the free version, “Community”.

STEP 4: Install PyCharm and launch, then proceed with “New Project”.

Introducing the Bot

Now that we’re done with setting up our coding platform, we shall move on to setting up the bot on discord. Here we’ll first add our bot to whatever server we like and also give it whatever permissions we want, most of them being text permissions as this is mainly a chatbot.

STEP 1: Google “Discord Developer Portal” and click on the first link. Select “Applications” on the left-hand side of the screen and then click on “New Application” and give it a name, any name you like.

STEP 2: After that, in “Settings”, go to “Bot”, give it a name and profile picture (if you want to) and copy the token link. After doing that, scroll down and switch off “Public Bot”(So no one except you can add the bot in any server) and “Message Content Intent”(So your bot is allowed to receive message content).

STEP 3: Now click on the OAuth2 tab, then “URL Generator” under that. In this, You have to tick “bot” in scopes for you to see and edit bot permissions.

STEP 4: Scroll down to the bottom of the page, you will see “Generated URL”. This is where we copy the URL to invite our bot to whatever servers we like.

STEP 5: After you’ve copied it, simply paste the link onto a new tab on your browser and press enter. You will be asked to choose a server and then authorization.

Now you can open up your server and see that your bot has made its presence!

You will also notice it being offline. Now, of course, to get it to work we need to give it a sturdy code, which in this case will be super easy.

Getting the Bot Alive

STEP 1: Now we’ll come back to PyCharm and paste the token we copied initially, into a variable.

Note: Every single bot you create has a unique token link of its own so copying the one shown here will not work.

STEP 2: To be able to link our program up with Discord, we’re going to have to import the Discord library here. We can do so by simply opening up the terminal at the bottom and typing “pip install discord” in it.

STEP 3: After installing discord, we’ll create a new python file under the same project for the responses that your bot’s going to respond to by right-clicking on your project’s name -> New -> Python File.

STEP 4: After we’ve created the “responses” file, just copy paste this source code.

import random
def get_response(message: str) -> str:
p_message = message.lower()

if p_message == 'hello':
return 'Hello there!'

if message == 'roll':
return str(random.randint(1, 6))

if p_message == '!help':
return '`Heh you wish`'

if p_message == 'what':
return 'bruh, you stupid'

return "I did not understand what you wrote. Try typing \"!help\"."

p_message here stands for whatever message the user inputs. You can edit it to anything you want the bot to respond to.

STEP 5: After we’ve created whatever responses we want the bot to respond to, we’ll go back to our bot file and import discord and responses. Follow this code:

import discord
import responses

async def send_message(message, user_msg, priv_msg):
try:
response = responses.get_response(user_msg)
await message.author.send(response) if priv_msg else await message.channel.send(response)

except Exception as e:
print(e)

def run_discord_bot():
TOKEN = 'MTA5MDMxOTcwOTY3ODg3MDYzMA.GRlRIZ.6PLWbf1mbUzQzbUl9rLQKx8kuHQ1F9xvDqKTJ8'
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)

@client.event
async def on_ready():
print(f'{client.user} is now running!')

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

username = str(message.author)
user_msg = str(message.content)
channel = str(message.channel)

print(f'{username} said: "{user_msg}" ({channel})')

if user_msg[0] == '?':
user_message = user_msg[1:]
await send_message(message, user_msg, priv_msg=True)
else:
await send_message(message, user_msg, priv_msg=False)


client.run(TOKEN)

NOTE: Remember to change the TOKEN=’ ’ into whatever your bot’s token link is or this will NOT work.

STEP 6: We’re almost done with getting our bot to work! The last step would be to import the bot itself, so we create another python file the same way we did with “responses”, I’ll name it main. This is where we’ll import our bot. Now, you just have to run the following code and your bot will come online!

import bot
if __name__ == '__main__':
bot.run_discord_bot()

This is what it looks like:

Now we’re ready to interact!

This is what my bot looks like. I’ve only added so many responses but you can add so much more!!

In under 15 minutes, we’ve downloaded Python, created a bot on discord and gotten it to work. Easy, isn’t it? So picture the level of bot one can make with advanced knowledge of Python and just a little bit more time. This was a very basic level bot for all of us impatient lads, but next time, we shall strive to do much, much better!

--

--