Search code examples
node.jsdiscorddiscord.jspm2forever

How do I keep my discord bot online even with my terminal closed


I have a pretty simple discord.js bot and would like to keep it running even when I close my terminal and/or my computer.

I have already tried pm2 and just keeping my terminal open throughout the day, but it wastes battery.

I keep running pm2 run NAMEOFFILE.JS in the right folder, but it already says I'm running the file.


Solution

  • EDIT: Yeah use PM2 or some other application, screen is a bad idea.

    If you're on either MacOS or Linux, you can use the screen command (Or cygwin on Windows). It basically creates another terminal. To use it you can do screen -R <name>.

    When you use the -R <name> (capital) the computer will look for a screen with the name and reattach to it. If it can't find a screen with that name it will create a new screen with that name.

    So for you, you might do screen -R Discord. After you attach to the screen you can do whatever you want as if it were a terminal. When you're done, you can press ctrl+a then d to detach from the screen, then you can close the terminal window.

    https://ss64.com/osx/screen.html