skip to Main Content

I have a problem that when I want to turn on my discord bot on my server that uses cPanel, I can’t get it to work from the node.js control panel without putting the shell command node index.js into the package.json file and using the run script function of the panel. the problem with this is that the only way to stop the bot is to use the eval command on discord, since I don’t have proper terminal access.

3

Answers


  1. On cPanel you will never have full terminal access, so what I suggest you do is just keep the NPM start script, then create a command for the bot that issues the process.exit() function. This function essentially stops the entire NodeJS Process. If you are looking for an alternative that provides full terminal access I recommend buying a cheap VPS from a decent provider such as OVH.

    Login or Signup to reply.
  2. In addition to what @Verdigris answered above, you can use Glitch too, just make sure to use Runtime Bot so you can keep your Discord bot up 24/7.

    Important: code to add on your main node.js file:

    const http = require('http');
    const express = require('express');
    const app = express();
    app.get("/", (request, response) => {
    console.log(Date.now() + "Ping Received");
    response.sendStatus(200);
    });
    app.listen(process.env.PORT);
    setInterval(() => {
    http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
    }, 280000);
    

    And as always, cheers.

    Login or Signup to reply.
  3. If your cPanel account has a in-browser terminal, you can enter the virtual environment by pasting the command that appears at the top of the Node.js control panel into there. It is something like:

    source ~/nodevenv/<name_of_node_application>/10/bin/activate && cd ~/<path_to_node_application>
    

    You will then have access to node and npm, and can then start your discord bot like you normally would like:

    node <name_of_node_application> &
    

    and kill it by running kill -TERM with node’s pid, from ps -ax.

    However, you can’t reliably use the Node.js panel to stop a daemon script, as described here:
    cpanel node.js Can't acquire lock for app: app

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search