NEW 📢 Black Friday: our launch offer ends 30 Nov. Up to 70% off your first month on every game!See plans
Black FridayUp to 70% off your first month, ends 30 NovEnds in 9d 03h 22mBlack FridayUp to 70% off your first month, ends 30 NovEnds in 9d 03h 22mBlack FridayUp to 70% off your first month, ends 30 NovEnds in 9d 03h 22m

How to host a Pycord bot 24/7

Discord bot hostingUpdated Nov 6, 202610 min read

To host a Pycord bot 24/7, run it on a machine that stays on instead of your PC: a Linux VPS with a systemd service if you host it yourself, or a bot plan on PlayNHost Discord bot hosting (from US$1.99 a month), where you upload your code, paste the token and press Start. In our test a Pycord 2.8.1 bot used about 51 MB of memory and reached Discord about 1.1 seconds after it was launched. Pycord installs as py-cord but you import it as discord, the same name as discord.py, so list only one of the two. The steps on PlayNHost:

  1. On the Discord bot hosting page, click Create Server on a plan. In the order window, answer What is your bot for? with Discord and pick Python.
  2. Open your server in the panel. The Set up your bot card on Overview opens at Connect to Discord. Its first step, What runs, should say This bot runs Python Bot.; click that step to check it, then Continue.
  3. At Connect to Discord, paste your token into Paste your bot token, click Connect, then Yes, continue.
  4. At Permissions, tick My code uses this only for the privileged intents your code asks for (the bot below needs none), click Add to a Discord server, then Continue.
  5. At Your code, click Upload files and upload bot.py and a requirements.txt that lists py-cord, or click Connect Git.
  6. If your main file is not bot.py, set the Entry file on the Bot page, pane Code, and click Save.
  7. Click Start bot and watch Console. When your bot prints Logged in as ..., the card says Your bot is online in Discord.

The general Python steps (runtime, packages, console lines) are in How to host a Python Discord bot. This page covers what is different with Pycord.

What we measured

We ran each Python Discord library on our own servers, in the same Python 3.12 setup a bot plan uses, with a 1 GB memory limit:

LibraryVersionMemory at restStart to Discord's answer
Pycord2.8.151 MB1.1 s
discord.py2.7.148 MB1.0 s
nextcord3.2.047 MB1.0 s
disnake2.12.247 MB0.9 s
hikari2.7.061 MB1.3 s
Python alone3.129 MB

How: the smallest program that loads the library and logs in with a fake token, installed the way our servers install it. Memory is what the process held 15 seconds after Discord refused the token, and start time runs from launch to that answer, so it includes one trip to Discord. Each figure is the median of three runs after a warm-up run. It is the floor: a bot that has connected, joined servers and cached members uses more, by an amount that depends on the bot.

What it means for the plan: a minimal Pycord bot takes about a tenth of the 0.5 GB STARTER plan. Size the plan for what your own bot keeps in memory, not for the library.

A minimal Pycord bot

It answers /ping with a slash command and prints a ready line. It reads the token from DISCORD_TOKEN, the name the panel gives your code.

requirements.txt

py-cord>=2.8,<3

bot.py

import os

import discord

bot = discord.Bot()


@bot.event
async def on_ready():
    print(f"Logged in as {bot.user}")


@bot.slash_command(name="ping", description="Check that the bot answers")
async def ping(ctx: discord.ApplicationContext):
    await ctx.respond("Pong!")


bot.run(os.environ["DISCORD_TOKEN"])

discord.Bot is Pycord's own class for slash commands. It registers /ping with Discord by itself each time it connects, because auto_sync_commands is on by default, so there is no sync step to write. The Logged in as line is what turns the chip on Overview to Online in Discord.

If the token is wrong

When Discord refuses the token, Pycord raises this error (the text our test bot printed):

LoginFailure: Improper token has been passed.

With bot.run() it ends a traceback as discord.errors.LoginFailure: Improper token has been passed. and the bot stops. The panel reads that line: the chip shows Token problem and a banner says Discord did not accept your bot token. Get a new token in the Discord Developer Portal: your application, Bot, Reset Token (it is shown once). Click Replace the token in the banner, then Replace token on the Discord pane, paste it and start the bot again. See How to create a Discord bot and get its token.

What a host needs to know about Pycord

  • Install name and import name differ. You install py-cord and write import discord. discord.py installs a module with the same name, discord, so the two cannot live side by side. Pycord's own guide says to uninstall discord.py first, and warns that uninstalling discord.py after installing py-cord can cause issues.
  • Moving a server from discord.py to Pycord. Our servers install packages into a .local folder and never remove one you take out of requirements.txt, so discord.py would stay next to Pycord. In Files, delete the .local folder and the file .pnh/packages.state, then press Start: everything in requirements.txt installs again, without discord.py.
  • Python version. Pycord 2.8.1 supports Python 3.10 to 3.14. The Runtime on the Code pane offers exactly these, with 3.12 as the default, so any choice works.
  • Intents. discord.Bot() uses the default intents, which include no privileged one, and slash commands need none. Prefix commands such as !ping need intents.message_content = True in your code and Message Content Intent switched on in the Developer Portal. If your code asks for it while it is off in the Portal, Discord refuses the login. See Fix "Used disallowed intents" on your Discord bot.
  • Keep on_connect free. The automatic registration runs in the bot's own on_connect. If you define on_connect yourself, Pycord's documentation says to call await bot.sync_commands() in it, or your commands stop updating. Put start-up code in on_ready, as above.
  • Logging is off unless you turn it on. Pycord's run() does not set up logging, so Python shows only the library's warnings and errors, not its info lines such as the login. Print your own ready line, as above, or call logging.basicConfig(level=logging.INFO) to see what the library is doing.
  • Voice. For voice channels, write py-cord[voice] in requirements.txt instead of py-cord.

Host it yourself on a Linux VPS

On Debian or Ubuntu, install Python, create a user and a folder for the bot, and install Pycord in a virtual environment:

sudo apt update
sudo apt install -y python3 python3-venv
sudo useradd --system --create-home --home-dir /opt/pycord-bot bot
sudo cp bot.py requirements.txt /opt/pycord-bot/
sudo chown bot: /opt/pycord-bot/bot.py /opt/pycord-bot/requirements.txt
sudo -u bot python3 -m venv /opt/pycord-bot/venv
sudo -u bot /opt/pycord-bot/venv/bin/pip install -r /opt/pycord-bot/requirements.txt

Put the token in a file only root can read. Create /etc/pycord-bot.env with sudo nano /etc/pycord-bot.env, write one line, DISCORD_TOKEN= followed by your token, save it and run sudo chmod 600 /etc/pycord-bot.env.

Then create /etc/systemd/system/pycord-bot.service:

[Unit]
Description=Pycord Discord bot
Wants=network-online.target
After=network-online.target

[Service]
User=bot
WorkingDirectory=/opt/pycord-bot
EnvironmentFile=/etc/pycord-bot.env
Environment=PYTHONUNBUFFERED=1
ExecStart=/opt/pycord-bot/venv/bin/python bot.py
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Start it now and at every boot, then follow its output:

sudo systemctl daemon-reload
sudo systemctl enable --now pycord-bot
sudo journalctl -u pycord-bot -f

PYTHONUNBUFFERED=1 makes print() reach the journal at once instead of when a buffer fills. To update the bot, copy the new files, run the pip install line again and sudo systemctl restart pycord-bot.

Self-hosting or a bot plan

Your own VPSA PlayNHost bot plan
PythonThe version your distribution ships; you install and update itPick 3.10 to 3.14 under Runtime
PackagesYou run pip install after each changeInstalled at a start after requirements.txt or the Python version changes, and at the first start a day after the last install
RestartsYour systemd unitStarted again after a crash; left stopped with the reason if it crashes again within a minute
The tokenA file you protect yourselfStored encrypted, checked with Discord when you paste it, given to your code as DISCORD_TOKEN
ErrorsYou read the journalThe console banner names the cause, such as a wrong token or a missing intent
System updates, firewall, SSHYours to doNot your job

Questions people ask

Can I have Pycord and discord.py in the same bot?

No. Both install the module discord, so one overwrites the other. Keep only py-cord in requirements.txt. If the server ran discord.py before, delete .local and .pnh/packages.state in Files so the packages install again cleanly.

Why does /ping not show up in my server?

Check the bot was added with Add to a Discord server and that the console shows the Logged in as line: Pycord registers the command when it connects. While you test, pass debug_guilds=[your_server_id] to discord.Bot(): the commands are then created only in that server, and Discord's documentation says server commands update instantly.

Is Pycord the same as discord.py?

No. Pycord started as a fork of discord.py and keeps much of its API, such as discord.Client and discord.ext.commands, but its slash commands differ: @bot.slash_command and ctx.respond() in Pycord, app_commands and a sync call in discord.py. Code written for one does not always run on the other.

Does a Pycord bot fit the smallest plan?

Yes. At about 51 MB in our test, a minimal Pycord bot uses about a tenth of the 0.5 GB STARTER plan. Move up when your bot itself needs it: large servers whose members it caches, files or images it handles, or data it keeps in memory.

Ready to run yours? Pick a plan on Discord bot hosting and upload your Pycord bot.

Already hosting your bot somewhere else? Move it to us

OUR LATEST BLOGS