← All guides

Bots & voice · Server guide

How to host a Discord bot 24/7 with Python: discord.py setup, tokens and logs

How to keep a discord.py bot online around the clock: requirements.txt, keeping the token secret, intents, logging and restarts, and running it on GGHOST Cloud.

GGHOST Cloud team26 October 20266 min read

Discord bot (Python)
  • Starts at On request
  • Recommended RAM Sized for you
  • Ready in A few days
  • Control panel Pterodactyl

Writing a Discord bot in Python is quick. Keeping it online is the harder part. A bot only answers while its process is running, so a script on your own PC stops the moment the machine sleeps, restarts for an update or loses its connection. Moving it to a server keeps it connected day and night, restarts it if it crashes, and still lets you read its logs and edit its files whenever you like. This guide covers how to prepare a discord.py project for a server, keep the token safe, and run it reliably.

Why host it instead of running it at home?

A home PC is ideal for writing and testing a bot. It is a poor place to run one that a community depends on. It has to stay switched on, home connections drop, and when the script crashes at three in the morning nobody is there to start it again. A small hosted container is always on, restarts the process for you, and gives you a console you can check from anywhere.

What resources a Python bot needs

A typical bot spends almost all of its time waiting for events from Discord, so its needs are small: a little CPU and a modest amount of memory.

The things that raise them:

  • How many servers it is in. discord.py keeps a cache of guilds, channels and members, and that grows with the bot.
  • Member caching. Requesting full member lists for large guilds uses noticeably more memory.
  • Heavy libraries. Image processing, data science packages or audio work cost more than the bot itself.

Start small and watch memory use in the panel. If it keeps rising over days, size up; if it stays flat, you are fine.

Setting up the project

requirements.txt

List every package the bot needs in requirements.txt, one per line, starting with discord.py. If the bot uses voice, install discord.py[voice] instead, which adds the extra libraries voice needs. Pin the versions you have tested so the server installs the same ones. Working in a virtual environment locally and running pip freeze > requirements.txt from it is the simplest way to get an accurate list.

Choose a Python version on the server that the discord.py release you use supports. Its documentation lists the minimum.

One clear entry file

Keep a single file that starts the bot, such as main.py or bot.py. On the server, the startup settings point at that file, so a predictable name makes life easier for anyone else who works on it.

Keep the token out of your code

The bot token is its password. Anyone with it can log in as your bot and do anything its permissions allow. Never write it into main.py and never commit it.

  • In code, read it with os.environ["DISCORD_TOKEN"] and pass it to bot.run().
  • Locally, keep it in a .env file loaded with python-dotenv, and add .env to .gitignore.
  • On the server, set it as a startup variable in the panel, so it never sits in your files.

Search your project history for the token before you push it anywhere. If it was ever committed, assume it has leaked and reset it, even if a later commit removed it.

Intents and permissions

discord.py asks you to say which events the bot wants. Start from discord.Intents.default() and switch on only the extras you need, such as intents.message_content = True for prefix commands.

Server Members, Presence and Message Content are privileged intents. Each one has to be enabled under the Bot tab in the Discord Developer Portal before the bot can use it, and verified bots need Discord’s approval to keep them. Slash commands, built with app_commands, do not need Message Content, which makes them the tidier choice for new bots. Remember to sync the command tree so Discord knows about them.

Treat permissions the same way. Generate an invite link with only the permissions the bot uses, not Administrator.

Keeping it running and reading logs

  • Auto-restart. If the process exits, the panel starts it again. A bot that crashes on every start will still loop, so check the console after repeated restarts.
  • Use logging, not just print. discord.py configures logging when you start it with run(). Add your own messages through the logging module so they carry timestamps and levels.
  • Handle command errors. An error handler for commands keeps one bad input from filling the log with tracebacks and tells the user what went wrong.
  • Avoid blocking calls. discord.py is asynchronous. A long time.sleep() or a slow synchronous request freezes the whole bot; use asyncio.sleep() and async libraries instead.

Updating the bot

  1. Test the change on your own test server first.
  2. Upload the changed files over SFTP or the file manager.
  3. If you added or upgraded packages, upload the new requirements.txt too.
  4. Restart from the panel and watch the console until the bot logs in.

Before upgrading discord.py across a major version, read its migration notes. Major versions change how intents, commands and extensions work.

Security habits

  • Reset the token when in doubt. In the Developer Portal, open the Bot tab and choose Reset Token. The old token stops working immediately; update the startup variable and restart.
  • Give helpers their own access. Add them as sub-users in the panel with only the permissions they need, rather than sharing a login.
  • Update packages deliberately. Check for outdated packages regularly, and update one thing at a time so you know what broke.

Backups

Your code should be in git, but the server holds things git does not: SQLite databases, JSON data files, config and logs. On GGHOST Cloud, backups run on a schedule you set and restore from the panel without opening a ticket. Take a manual one before any large change as well.

Getting your bot on GGHOST Cloud

Python bot hosting is set up on request, so we can size it around what your bot actually does.

  1. Tell us what you need. Ask us on Discord (or open a ticket) with the Python version, roughly how many servers the bot is in, and any heavy libraries it uses.
  2. Get a quote. We size it, quote a monthly price, and set it up on our Pterodactyl panel, usually within a few days.
  3. Upload your code with requirements.txt over SFTP or the file manager. Packages install from it on boot.
  4. Set the token as a startup variable, start the server and wait for the login message in the console.

You get the full panel at panel.gghost.cloud: live console and logs, file manager, SFTP, startup variables, scheduled tasks and sub-users, with auto-restart if the process exits. Every node is behind DDoS protection from our network providers. Live regions today are Singapore and Europe (France–Germany border), with the United States (East, Central and West), the United Kingdom, India, Japan and Australia on demand. There is no setup fee and no contract, billing is at app.gghost.cloud, and support comes from the people who run the servers, on Discord or at hello@gghost.cloud.

The short version

List and pin your packages in requirements.txt, read the token from an environment variable, and enable only the intents you use. Use logging, keep everything asynchronous, back up any data that is not in git, and let the server restart the bot so it stays online when your PC is off.

How it works at GGHOST Cloud

From request to running server.

  1. 01 Ask on Discord Tell us the Discord bot (Python) build, mods and player count you need.
  2. 02 We size it We recommend the RAM and region, and quote a monthly price.
  3. 03 We set it up Installed on our Pterodactyl panel, usually within a few days.
  4. 04 Invite your players Console, file manager, SFTP and backups, all in one panel.

Included on every server

The platform behind your Discord bot (Python) server.

Full Pterodactyl panel

Console, file manager, SFTP, scheduled tasks, sub-users and database access. Not a cut-down skin over it.

Backups on a schedule

Set the cadence you want and restore to a point in time from the panel, without opening a ticket.

DDoS protection included

Every node sits behind DDoS protection from our network providers, on every plan — not an upsell on the checkout page.

Switch version or build anytime

Change the server build, game version or startup flags from the panel and restart. No reinstall, no ticket.

Move region once per cycle

If your players move, the server can follow. We handle the world and config transfer.

No player-slot billing

You pay for memory. Slots are a config value you set, not a line item we charge for.

Discord bot (Python) server FAQ

Questions players ask us.

Why do my print() messages show up late, or not at all, in the console?

When Python is not writing to a terminal it buffers output. Use print(..., flush=True), run Python with -u, or set PYTHONUNBUFFERED=1. Better still, use the logging module, which discord.py already sets up when you start the bot with run().

Can I use a virtual environment on the server?

You do not need one. The container is already isolated for your bot, and packages install from requirements.txt when it boots. Keep using a virtual environment locally so requirements.txt only lists what the bot really uses.

Want a Discord bot (Python) server?

Tell us what you need on Discord and we will size it and set it up on our Pterodactyl panel.