Coding a Discord Bot With Python!

A simple walkthrough of using on replit

Posted by AwesomeAg on 04-21-2020

So… you’ve probably heard of discord, a chat and stream app for gamers. Over time it has evolved but it is still there for one main thing: chatting. Nowdays, you can create bots for discord that act as users and put some fun into discord with games, moderation, and trolling. Bots can be coded in many different languages, and it’s pretty common to make one in discord.js or
A bot
To start, you need to open and start a new python code. Write

import discord

on the first line
but before that, go to the packages section and search discord to install it.
To host the bot, create a new file and name it Now type the following into the file

from flask import Flask
from threading import Thread
app = Flask('')
def main():
return "Bot is online"
def run():"", port=8080)
def keep_alive():
server = Thread(target=run)

now go back to
Before you start coding, you need to create the actual discord bot. you can do this by going here
and then press the button that says new application in the top right:
New app button
Name it whatever you want, but when you’re done, go to the section that says bot
bot button
and click it.
You should see a screen like this screen with bot
Now to bring it to life, press add bot and then press “yes do it”. You can name it and edit the profile picture, but the big part is copying the token copy token
now head back to the file and at the end of it, write the following:

import keep_alive #this should be the name of the file that you created earlier
await"TOKEN") #replace token with your token.

now head back to the beginning of the file, where you imported discord. There, type

client = discord.Client()
bot = commands.Bot(command_prefix="!", description='My new bot!') #You can change the prefix if you wanr

Congrats! You have officially made your discord bot! It doesn’t do anything yet, but one last step before we finish is inviting it to a server.
If you scroll to the bottom of the OATH2 page (the sidebar next to bot), you will see this: panel
click on “bot” and another panel will appear. On this new panel, click “Administrator” and copy the generated link at the bottom.
go to the link you copied and invite it to a server. I would recommend making a testing server for this.
PERFECT! Your bot is up on a server, but it doesn’t do anything yet 😞. Well, stay tuned for part 2 on how to make commands, send embeds, and more! Go ahead and check the code here documentation (the docs)
And check out the second part here!