
A Discord bot is only useful while it's online. Run it on your own PC and it disappears every time the PC sleeps, restarts or loses its connection. Here's how to set a bot up properly, keep its token safe, and run it on a server that keeps it online around the clock, with examples for both discord.js and discord.py.
Create the bot in the Discord Developer Portal, copy its token and invite it with the OAuth2 URL generator. Read the token from an environment variable, never from your code. Upload your project to an always-on host, set the start file and the DISCORD_TOKEN variable, and let the host restart the bot if it crashes. A small bot runs fine on 1 GB of RAM.
| Where it runs | Cost | What happens |
|---|---|---|
| Your own PC | Free | Goes offline when the PC sleeps, restarts or loses internet |
| Free hosting tiers | Free | Usually sleep when idle, limit hours or restart without warning |
| Bot hosting | A few dollars a month | Always on, restarts after a crash, no PC needed |
A bot is a program that has to keep running to stay connected to Discord. When the program stops, for any reason, the bot shows as offline and stops answering. So "24/7" really means two things: a machine that's always on, and something that starts the bot again when it crashes.
!help), and Server Members only if it tracks who joins or leaves.bot and applications.commands scopes, pick the permissions the bot needs, then open the generated link and add the bot to your server.The token is the bot's password. Anyone who has it can log in as your bot and do anything it can do in every server it's in.
DISCORD_TOKEN..env file, add it to .gitignore. Discord resets tokens it finds in public repositories, which takes your bot offline.Save this as index.js, with a package.json that lists discord.js as a dependency. Use the Node.js version the discord.js docs ask for: it goes up over time, so check before you deploy.
const { Client, Events, GatewayIntentBits } = require("discord.js");
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, (c) => {
console.log("Logged in as " + c.user.tag);
});
client.login(process.env.DISCORD_TOKEN);Save this as main.py, with a requirements.txt containing discord.py.
import os
import discord
intents = discord.Intents.default()
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f"Logged in as {client.user}")
client.run(os.environ["DISCORD_TOKEN"])Both only connect and log a line, which is all you need to test hosting. Build your commands on top once it works.
node_modules and virtual environments: the packages from package.json or requirements.txt get installed on the server.index.js or main.py) in the panel's startup settings.DISCORD_TOKEN environment variable in the panel, so it never sits in your files.Less than you'd think. A typical moderation, utility or fun bot in a handful of servers uses well under 256 MB, so a 1 GB plan is plenty. You need more for music bots, which process audio, and for bots in thousands of servers, which keep large caches. Once a bot reaches 2,500 servers, Discord requires sharding, which discord.js and discord.py both support.
Our Discord bot hosting runs discord.js and discord.py bots around the clock and restarts them automatically within seconds of a crash. Upload your code with the file manager or SFTP, set your startup command and environment variables in the panel, and your bot is online. Daily backups and DDoS protection are included, and plans start at $0.99/month.
Yes, on your own PC or a free hosting tier, but expect downtime: the PC has to stay on, and free tiers usually sleep or limit hours. For a bot people rely on, a small paid plan is the reliable option.
Usually a missing intent (Message Content for prefix commands), missing permissions in that channel, or slash commands that haven't been registered yet. The console normally shows which.
Only if the bot reads the text of messages. Slash commands work without it. Bots in 100 or more servers need Discord's approval to use it.
Whichever language you know. Both are mature, well documented and support everything a normal bot needs.
Discord bot hosting from $0.99/month, with discord.js and discord.py support, automatic restarts and daily backups.