Host a Discord bot 24/7: discord.js and discord.py on the Pelican panel
This guide explains how to keep a Node.js or Python Discord bot online around the clock: token, intents, .env file, SFTP or Git upload, panel variables and troubleshooting.
By Salem ASSADI • Published 5 November 2026 • Updated 24 November 2026 • Related plan: Node.js or Python Discord bot
Why host a Discord bot on a server
A Discord bot is only online while its program is running. Started from your own computer, it stops as soon as the machine is turned off, goes to sleep or loses its connection. For a bot that is available around the clock, it has to run on a server that stays on permanently and restarts it if it stops. Good news: a regular bot opens an outgoing connection to Discord by itself, so there is no port to open.
This guide explains how to host a Discord bot 24/7 written in Node.js with discord.js or in Python with discord.py: creating the application and token, project structure, keeping the token out of the code, uploading files via SFTP or deploying from Git, Pelican panel variables, auto-restart, logs, updates and troubleshooting.
Prerequisites
- A Discord account and a Discord server where you have the "Manage Server" permission, to invite the bot.
- Your bot's code, or the minimal example provided below.
- Access to the panel.rxcorp.me panel: Console, Files, Schedules, Startup and Settings (SFTP details).
- An SFTP client (FileZilla, WinSCP) or a Git repository (GitHub, GitLab).
At RXCORP, the Discord Bot Node.js and Discord Bot Python plans cost €1.49/month each and include 512 MB of RAM, 2 GB of storage, the console and SFTP access. The server is delivered automatically within a few minutes of payment, with no commitment. Pick the plan that matches your bot's language.
Step 1: create the application and get the token
- Open the Discord Developer Portal and click New Application.
- In the Bot tab, click Reset Token and copy the token shown. It is only displayed once.
- Still under Bot, in the Privileged Gateway Intents section, enable only what the bot needs: Presence Intent, Server Members Intent and Message Content Intent (required to read the content of regular messages).
- Under OAuth2, then URL Generator, tick the
botandapplications.commandsscopes, choose the permissions you need, then open the generated URL to invite the bot.
Beyond 100 servers, Discord requires the bot to be verified and privileged intents to be approved.
Step 2: organize the project
Typical structure of a Node.js bot:
my-bot/
index.js
package.json
package-lock.json
.env
.gitignore
Typical structure of a Python bot:
my-bot/
app.py
requirements.txt
.env
.gitignore
The names index.js and app.py match the panel defaults; you can use others by adjusting the variables (step 5). The .gitignore file keeps the token and dependencies out of Git:
.env
node_modules/
__pycache__/
Step 3: keep the token out of the code
Never hard-code the token. Put it in a .env file at the project root:
DISCORD_TOKEN=paste_your_token_here
Node.js (discord.js)
package.json:
{
"name": "my-bot",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"discord.js": "^14.0.0",
"dotenv": "^16.0.0"
}
}
index.js:
require('dotenv').config();
const { Client, Events, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
client.once(Events.ClientReady, (c) => {
console.log(`Logged in as ${c.user.tag}`);
});
client.on(Events.MessageCreate, (message) => {
if (message.author.bot) return;
if (message.content === '!ping') message.reply('pong');
});
process.on('unhandledRejection', (err) => console.error(err));
client.login(process.env.DISCORD_TOKEN);
Python (discord.py)
requirements.txt:
discord.py
python-dotenv
app.py:
import os
import discord
from dotenv import load_dotenv
load_dotenv()
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f"Logged in as {client.user}", flush=True)
@client.event
async def on_message(message):
if message.author.bot:
return
if message.content == "!ping":
await message.channel.send("pong")
client.run(os.getenv("DISCORD_TOKEN"))
The intents declared in the code must match those enabled in the portal: here, Message Content Intent must be turned on.
Step 4: upload the files to the server
Option A: file manager or SFTP
- In the Startup tab, set
USER_UPLOADto1: the server will use your uploaded files instead of a Git repository. - Upload your files from the Files tab, or over SFTP using the host, port and username shown under Settings (the password is your panel account password).
- Do not upload
node_modules/: dependencies are installed on the server.
Option B: deploy from Git
- In Startup, fill in
GIT_ADDRESS(the repository's HTTPS URL) andBRANCH, and leaveUSER_UPLOADat0. - For a private repository, add
USERNAMEandACCESS_TOKEN: a read-only personal access token, never your password. - Cloning happens when the server is installed. If you set the repository afterwards, trigger a reinstall from Settings, after downloading a copy of your files.
- Enable
AUTO_UPDATE(1) so that agit pullruns on every start: deploying then simply means pushing to the branch and restarting.
Since the .env file is not in Git, create it directly on the server from the Files tab. A git pull does not touch untracked files.
Step 5: set the startup variables
| Variable | Node.js | Python |
|---|---|---|
| Main file | MAIN_FILE (default index.js) | PY_FILE (default app.py) |
| Dependencies | package.json + NODE_PACKAGES (extra npm packages) and UNNODE_PACKAGES (packages to remove) | REQUIREMENTS_FILE (default requirements.txt) + PY_PACKAGES |
| Git | GIT_ADDRESS, BRANCH, USERNAME, ACCESS_TOKEN | |
| Upload mode | USER_UPLOAD: 1 = uploaded files, 0 = Git | |
| Updates | AUTO_UPDATE: git pull on start | |
The startup command is provided by the template: it installs the declared dependencies and then runs the main file. There is nothing for you to write. If your library requires a specific Node.js or Python version, check the image offered in the Startup tab. Do not add a process manager such as pm2 or nodemon: the panel supervises the process.
Step 6: auto-restart and scheduling
If the process stops unexpectedly, the panel restarts it automatically. To avoid an endless loop, it does not restart it if the crash repeats within a very short time: the server then stays stopped and the console shows why. In your code, catch unhandled errors (like the unhandledRejection handler in the Node.js example) so that a single exception does not take the bot down. On the Python side, discord.py logs exceptions raised in event handlers by default without stopping the bot.
The Schedules tab also lets you add a periodic restart (Power action task, Restart), handy with AUTO_UPDATE to pick up the latest version of the repository on a regular basis.
Step 7: read the logs
The Console tab shows the program's output: everything the bot writes with console.log or print, plus errors. discord.py also sets up its own logging when started with client.run. In Python, output may be buffered: use flush=True or the logging module to see messages immediately. If you write logs to a file, rotate them regularly: you have 2 GB of space.
Step 8: update dependencies
- Node.js: change the versions in
package.json(also updatepackage-lock.jsonif you use it), upload the files and restart.NODE_PACKAGESandUNNODE_PACKAGESare for one-off additions and removals without touching the project. - Python: edit
requirements.txt, ideally with pinned versions, then restart.PY_PACKAGESlets you add a package on a one-off basis.
Always test a major library update locally before deploying it: version changes in discord.js or discord.py can break existing code.
Troubleshooting common errors
Invalid token
discord.js shows An invalid token was provided, discord.py LoginFailure: Improper token has been passed. Check that .env is at the root, that the variable name matches (DISCORD_TOKEN), that there are no stray spaces or quotes, and that the token has not been reset since.
Missing intents
discord.js returns Used disallowed intents, discord.py PrivilegedIntentsRequired: a privileged intent requested in the code is not enabled in the portal. If the bot works but message content is empty, Message Content Intent is either not enabled in the portal or not declared in the code.
The bot keeps restarting
Read the last console lines before each stop: syntax error, invalid token or missing dependency. Memory usage climbing up to 512 MB can also cause crashes; limit the data kept in cache.
Module not found
Cannot find module 'discord.js': the package is not declared in package.json, or that file is not at the root. Cannot find module '/home/container/index.js': MAIN_FILE does not match the actual file name. In Python, ModuleNotFoundError: No module named 'discord' means requirements.txt is missing or does not match REQUIREMENTS_FILE; for No module named 'dotenv', the package to install is called python-dotenv.
Conclusion
Hosting a Discord bot 24/7 comes down to a few rules: a token stored in .env and never published, intents that match between the portal and the code, dependencies declared in package.json or requirements.txt, and a panel that restarts the bot when it stops. To put it online for €1.49/month with console and SFTP, see the Discord Bot Node.js and Python plans. Support is available on Discord and through tickets. More tutorials are available in the guides section.