Unlike a website, a Discord bot doesn’t wait for visitors. It logs in once, holds a WebSocket connection to Discord’s Gateway, and reacts to events as they arrive. Hosting it means keeping that one process alive: start it detached from your SSH session, restart it automatically when it dies, and read its log when something goes wrong.
Prerequisites
- An AI/Developer plan with SSH access (see SSH access).
- An application in the Discord Developer Portal with a bot user.
- Bot code that works on your computer, in Python (discord.py) or Node.js (discord.js).
Step by step
1. Prepare the bot in the Developer Portal
- Open your application, go to Bot, and click Reset Token. Copy the token; it is shown only once.
- Under Privileged Gateway Intents, enable Message Content Intent if the bot reads message text, and Server Members Intent if it handles member events. Leave the others off unless you need them.
- Go to OAuth2 › URL Generator, tick the
botandapplications.commandsscopes and the permissions the bot needs, then open the generated link to invite the bot to your server.
2. Upload the code and install dependencies
Put the bot in its own folder, for example ~/bots/discord, with Git, SFTP or File Manager.
Python (discord.py):
cd ~/bots/discord
/opt/alt/python312/bin/python3.12 -m venv venv
venv/bin/pip install --upgrade pip
venv/bin/pip install -U discord.py
Node.js (discord.js):
cd ~/bots/discord
/opt/alt/alt-nodejs20/root/usr/bin/npm install discord.js
Because this folder is not an app created in Setup Node.js App, a normal node_modules folder here is fine.
3. Store the token
printf 'DISCORD_TOKEN=%s\n' 'PASTE-YOUR-TOKEN-HERE' > ~/bots/discord/.env
chmod 600 ~/bots/discord/.env
Never commit it. Discord scans public GitHub repositories and resets leaked tokens, and anyone with the token controls your bot.
4. A minimal bot
bot.py:
import os
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.message_content = True # must also be enabled in the Developer Portal
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event
async def on_ready():
print(f"Logged in as {bot.user} (id {bot.user.id})", flush=True)
@bot.command()
async def ping(ctx):
await ctx.send("pong")
bot.run(os.environ["DISCORD_TOKEN"])
bot.js:
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, (msg) => {
if (!msg.author.bot && msg.content === "!ping") msg.reply("pong");
});
client.login(process.env.DISCORD_TOKEN);
Test it in the foreground first (set -a; . ./.env; set +a; venv/bin/python bot.py), send !ping in your server, and stop it with Ctrl+C.
5. The keepalive script
Save as ~/bots/discord/keepalive.sh. Set CMD to the line for your language:
#!/bin/bash
APP="$HOME/bots/discord"
CMD="$APP/venv/bin/python $APP/bot.py"
# Node.js: CMD="/opt/alt/alt-nodejs20/root/usr/bin/node $APP/bot.js"
cd "$APP" || exit 1
pgrep -f "$APP/bot\.(py|js)" > /dev/null && exit 0
set -a
. "$APP/.env"
set +a
nohup $CMD >> "$APP/bot.log" 2>&1 &
echo "$(date '+%F %T') started PID $!" >> "$APP/keepalive.log"
Make it executable and run it once: chmod 700 ~/bots/discord/keepalive.sh && ~/bots/discord/keepalive.sh.
6. Schedule it with cron
In cPanel open Advanced › Cron Jobs, choose Once Per Five Minutes in Common Settings, and add:
/bin/bash /home/USER/bots/discord/keepalive.sh >/dev/null 2>&1
If the process exits for any reason, the next run brings it back. See setting up cron jobs for other schedules.
7. Update and monitor
To deploy new code, run pkill -f "$HOME/bots/discord/bot" and then the keepalive script. Follow the log with tail -f ~/bots/discord/bot.log.
Troubleshooting
discord.errors.PrivilegedIntentsRequiredorUsed disallowed intents: the code asks for an intent that isn’t enabled in the Developer Portal. See Discord disallowed intents.discord.errors.LoginFailure: Improper token has been passedorTokenInvalid: the token was reset, copied with a space, or.envwasn’t loaded.- Online but silent: Message Content intent is off in the code or the portal, or the bot lacks permission to read or send in that channel.
- Every reply arrives twice: two copies are running. Discord allows several sessions, so you get duplicates rather than an error. Check with
pgrep -af "bots/discord". - Frequent restarts in keepalive.log: read the end of
bot.log. Fix crash loops quickly, because Discord limits how many times a bot may start a new session per day. - Slash commands don’t appear: register them once (
await bot.tree.sync()in discord.py, or the RESTapplicationCommandsroute in discord.js), then reload the Discord client to see them.
On ArabyHost
Discord bots run on the AI/Developer plans, which include SSH jailed in CageFS, Python 3.9-3.12, Node.js 20 and 24, and background workers kept alive with cron as shown here. The bot shares your account’s own resource limits (LVE), so it suits text, moderation and utility bots; there is no Docker, no GPU and no root access. The same method runs other long-lived workers; see running a Telegram bot and Discord bot hosting.
FAQ
Can a Discord bot run on shared web hosting?
It needs a process that stays connected all the time, plus SSH to set it up. On ArabyHost that is the AI/Developer plans; shared, WordPress and email plans don't run background processes.
Why is my bot online but not answering messages?
It can't read message text. Enable the Message Content intent both in the Developer Portal (Bot › Privileged Gateway Intents) and in your code, for example `intents.message_content = True` in discord.py, then restart the bot.
Can I host a music bot this way?
Music bots transcode audio continuously with ffmpeg, which uses a lot of CPU and quickly reaches the limits of a shared account. Text, moderation and slash-command bots are a much better fit.