Make a bot run forever

Question:
How do I make my bot/bots run forever (even if my pc is off)

1 Like

Hey @JuriHusch welcome to the forums!

You can use deployments but they do cost money.

8 Likes

Alternatively check out Always On (costs 20 cents per day).

5 Likes

Note that ‘Always on’ will experience temporarily stops, but will immediately start again afterward, whenever Replit moves resources around.

2 Likes

Replit stops processing a Repl after 15 minutes of inactivity.
If you’re looking for a simple (and free) solution to host your program 24/7, follow these steps:

  1. Host a website usign your Node.js script. You can simply add this code to your current:
const express = require('express'); // Import the express library
const app = express(); // Launch the express app
const http = require('http'); // Import the http library
const server = http.createServer(app); // Create the server

/** Replying to request at '/' */
app.get('/', (req, res) => {
  res.send('Testing...'); 
});

server.listen(3000, () => { }); // Opening the 3000 port

It’ll host the website. View it on YOUR-REPL-NAME.YOUR-REPLIT-USERNAME.repl.co. You should see ‘Testing…’ printed on the screen.

  1. Setup a cron pinging to the site. I recommend using UptimeRobot (https://uptimerobot.com/). You’ll have to sign up in case you haven’t yet, then create a new monitor. Monitor type will be HTTP(s) and URL will be the url of the website.

After you successfully setup the cron, your repl should be running 24/7.

In case you need some more help, feel free to ask, I’ll try to answer as soon as possible.

2 Likes

5 posts were split to a new topic: Shortest Express apps

If you don’t want to go through the Node.js stuff, https://daki.cc/ is a good site. It’s free and has decent performance, but inactive servers get shut down regularly- it requires constant maintenance, but not as much as if you were hosting it on your own computer and running the program nonstop. To use the site, you’ll have to create an account using discord. The dashboard is https://dash.daki.cc/.

1 Like

Depending on what your bot actually needs to do, you might be able to use a reverse webhook (interactions endpoint)

For instance if it just needs to do something when a user executes a command you don’t need to have it connected to discord 24/7

Hello @JuriHusch! I would recommend making a url for that node.js project (if you can) and using uptimerobot to ping that url. This will keep it awake and active. Now I don’t code Node JS, but I have a python discord bot that has a flask server on a url and I have uptimerobot pinging it, now sometimes the bot will be down from time to time, but still, it is a free source.

I am trying to keep my coding journey free as in I don’t want to pay much for a Hacker or Pro plan, so if you want advice from along those lines, you can talk to me.

Also I am going to use this as an advertising for my discord bot! So everyone I have an AI discord bot that I need to get into 75 servers. You don’t need to use it, but it has to be a member of the server. I want to verify it, and to verify it, I need 75! So if you want it, go to https://gizmo-ai-discord-bot.mileswk.repl.co/! Please ya’ll, I would apriciate it. we are in 21 servers right now. Also I can take down this post if you do not like it.

you don’t need to ping it if its a reserved VM, and autoscale deployments don’t entirely work like that, autoscale is more likely to be used for webhooks

1 Like

I recommend using Replit-dis-uniter it has a Python verison as well.

1 Like

UptimeRobot works kinda well, I don’t know haw to make it have statuses as in “Playing With Python” under the name, but there is most likely a way to have it cycle, which makes the bot have something to do, and won’t go offline

Pretty sure if you make your server ping itself every 5 minutes or so, it will stay awake (not sure about Replit, but it works on Glitch)

1 Like

yeah works with glitch

not after the new deployments change tho :frowning:

yea :frowning: it sucks, but replit does that now.

1 Like

Thank you. I have been using Uptimerobot to ping my replit for months ago but recently it hasn’t been working plus the server url isn’t showing anymore (i.e …repl.co)

What method are you using to run your bot recently for 24/7?

Try deploying your bot as a Reserved VM if it has no web framework.

I don’t have any anymore. Since the deployment change, Gizmo has been a mess and so I am having trouble with that.

You can host it for free on Cloudflare or if you want to pay (or have pro) you can host it on a reserved vm or autoscale deployment.