Skip to content
Sign upLog in
← Back to Community

How to keep your discord bot running 24/7 without the Hacker Plan

Profile icon
IroncladDevHacker

I personally don't make discord bots but I helped my friend make one run all the time and it can be done in two simple steps.

Once you finish your discord bot, attach a simple web server into it. If using discord.js, set up a simple "Hello World" web server and if using discord.py, simply make a flask server.

Javascript

Add a simple express server at the end of the code.

//...Discord Bot Code Above ^^ const express = require('express') const app = express(); const port = 3000; app.get('/', (req, res) => { res.send('Hello World!') }) app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`) })

Make sure you run npm install express in the terminal!!

How to do it in python.

To set up a flask server, simply add this code to the end of your python file:

#python discord bot code above ^^ from flask import Flask app = Flask(__name__) @app.route('/') def index(): return "Bot up and running" if __name__ == '__main__': app.run(host="0.0.0.0",debug=True,port=8080)

also, run pip install flask in the terminal.

After that's done, your repl will still fall asleep. To fix that, make an account at uptimerobot and add your repl domain or link. It should look like ReplName.YourUsername.repl.co

After that, make sure you RUN your repl

and everything should be up and running.

Voters
Profile icon
lazysloth22011
Profile icon
joemama12122
Profile icon
DavidJones24
Profile icon
SBtrains
Profile icon
TonyWu4
Profile icon
PixiGem
Profile icon
SleepySid
Profile icon
MaciahLawson
Profile icon
JaredBradyBrady
Profile icon
xfinnbar
Comments
hotnewtop
Profile icon
mi-catcat

Can run is bash?

Profile icon
CholO1

@app
.route('/')
Could you fix this lol. I'm clueless

Profile icon
abhiramtx

It says invalid syntax for the python one:

@app
.

Profile icon
syafiqdev

I have Alternative UptimerWeb Beside UptimeRobot, Uptime Kuma, fork this Repl : https://replit.com/@KabinKashyap/uptime-kuma and RUN it, after tht open the website of tht replit, and thn Create Acc. If u still confuse to use Uptime Kuma, watch this Vid : https://www.youtube.com/watch?v=klmkw6bWsjQ&t=56s

Profile icon
DaddE23

@syafiqds99
does up timer work for chromium-browser in python?

Profile icon
IroncladDev

@DaddE23
Chromium browsers are against the rules on replit. Also, monitors won't work with them.

Profile icon
DucTan2077

do I have to replace anything in the code? sorry I'm dumb

Profile icon
SpyderGamer

Wait, so if I press stop, the bot will still run or not?

Profile icon
IroncladDev

@HamzaMou244
If you press stop, it will stop your bot

Profile icon
SpyderGamer

@IroncladDev
Oh right, what about closing the tab or browser?

Profile icon
IroncladDev

@HamzaMou244
If you manually terminate your repl, this technique will not keep it going forever.

Profile icon
SpyderGamer

@IroncladDev
Right, but Replit keeps updating packages like every single day, which stops my repl. Is there a way to fix that?

Profile icon
IroncladDev

@HamzaMou244
Don't use pip install. Use python -m poetry add [package]

Profile icon
SpyderGamer

@IroncladDev
No i mean cuz it already adds the packages automatically (when I add import discord or something)

Profile icon
WillingDude

is there a way to use this outside of repl? ie, vscode

Profile icon
EricPlayzYT

@WillingDude
yes there is a way. You just need to import flask(python) or express(node.js) and set it to a port. Once you go to that port, set a ip/port monitor on uptimerobot.com and your done! Also copy the code above in the post. You might actually need to assign this to a domain if you want.

Profile icon
MagnusOelsner

...

Profile icon
MagnusOelsner

Where Do I add This Line Of Code For Java

Profile icon
IroncladDev

@MagnusOelsner
, idk how to do java

Profile icon
VulcanWM

Just saying commenting in Python is #

Profile icon
IroncladDev

@VulcanWM
, ooch, I accidentally pasted that I think lol