This is a tutorial on how to make a Discord Bot with the discord.py library along with a 24/7 uptime. This project should take anywhere from 15 to 45 minutes.
Make sure you sign up for the following platforms before proceeding. Since this project will be completely in the cloud, there are no installations necessary for this project.
This is the platform where your bot will operate
This is where you will create the platform for your bot to function on
- Go here
- Read this short article and create your server
- Name the server
Replit Bot Testing
This is where you will create an application for your bot
- Go to the Discord Developer Portal
- Click
New Application - Name it
Replit Bot
This where you make the bot for your application
- Go to the
π§© Botsection - Click
Add Bot - Click
CopyunderClick to Reveal Token - Paste and store this token in a text file on your device (will be used later)
You will need to invite the bot to a Server in order to make it function
- Go to the
π General Informationsection - Click
CopyunderApplication ID - Go here and paste the Application ID
- Select your previously made server and click
Authorize - Once done, go back to Discord to check for confirmation
This is the platform where you will host and run the code for the bot
- Go here
- Make a new repl
- Select Python as the language
- Name it "Discord Application" or anything else you want
- Add a
keepAlive.pyfile as shown below
- Create an environment variable as shown below and use your previously saved token for the value
- If you do not have your token, go back here and retrieve it
You will now implement the necessary tools to boot up the bot
This code will be the framework of your bot. It contains a few commands and events to demonstrate the layout of the discord.py library usage. You can add more commands/events later as you read through the documentation. For now, paste this code into your repl's main.py file.
This code that will allow your application to run 24/7. Paste it into your repl's keepAlive.py file
from flask import Flask
from threading import Thread
import random
app = Flask("")
@app.route("/")
def home():
return("Online!")
def run():
app.run(host = "0.0.0.0", port = random.randint(2000, 9000))
def keepAlive():
thread = Thread(target = run)
thread.start()
The last step of this tutorial is to set up the UptimeRobot monitor
- Click
βΆοΈ Runon the top of your repl - Copy the URL in the top right of your screen (mine was
https://Replit-Bot.hdadhich01.repl.co) - Go to your UptimeRobot dashboard and add a new monitor
- Fill out the fields as shown below, and use your own repl's URl for the empty field
Click Create Monitor, and that's it. You have completed building your Discord Bot!
Go to your previously created server and test out the following commands.
!help- displays a list of all commands!hello- says hello back!ping- displays the application latency!predict <question>- predicts the outcome of your question!color <hexCode>- displays the given color code in an embed!dm <user> <message>- sends a direct message to the specified user
If you encountered any issues, feel free to direct message me on my Discord found here!






