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 temporarily be stopped but immediately afterward as 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