ACLClouds
ACLClouds

Host a Discord Python bot with discord.py

requirements.txt, start file, logs: the steps to put a discord.py bot online and understand why it stops.

A bot written with discord.py is made of a few files: the code, the list of dependencies and a start file. Once these three are ready, hosting means uploading them, installing the dependencies, starting the bot and reading the logs when something goes wrong.

  • A discord.py bot is made of three files: the code, requirements.txt and the start file.
  • The token never belongs in the code or in Git.
  • The logs give the cause: read the last exception before restarting the bot.

Prepare the files

The bot should fit in a simple folder. Keep the token out of the code (see the article on environment variables) and list the dependencies in a requirements.txt file, which the installation reads line by line.

  • bot.py: the start file, the one that creates the client and calls client.run().
  • requirements.txt: one package per line, for example discord.py>=2.3 for the minimum version you tested.
  • A local .env file for your tests only: it must never reach the server or Git.

Install and start the bot

On a Python environment, the command to install the dependencies is the same as on your PC. Once the packages are installed, the bot starts from its start file.

  • pip install -r requirements.txt: installs the listed packages.
  • python bot.py: starts the bot locally to check that it connects.
  • If the console reports a start file it cannot find, it searches the sub-folders and offers a one-click fix.

Read the logs

The logs are the first place to look. A bot that stops almost always leaves a trace: a Python exception, a refused login or a token error.

  • A Traceback followed by an exception name: the file and line it points to are the code to fix.
  • discord.errors.LoginFailure: the token is missing or invalid, see the article on common Discord bot errors.
  • Privileged intents: Message Content must be enabled in the Discord developer portal if your code reads message text.

Why ACLClouds for a discord.py bot

The free plan gives 1 bot, 315 MB of RAM, 0.25 vCPU and 715 MB of storage. ffmpeg, yt-dlp and deno are already installed, and each bot has its own SFTP access.

  • Free plan: 1 bot, 315 MB of RAM, 0.25 vCPU, 715 MB of storage, uploads up to 100 MB.
  • The Python image includes ffmpeg, yt-dlp and deno.
  • SFTP access per bot on port 2222, to upload your files with FileZilla.

Frequently asked questions

Which Python version does discord.py need?

discord.py 2.x needs Python 3.8 or newer. For a new project, use a recent version that is still maintained.

The bot connects but does not answer messages. Why?

Check that the Message Content intent is enabled in the developer portal, then that the bot can read and send messages in the channel.

Can the bot run with my PC switched off?

Yes, that is the point of hosting: the bot runs on the server. Still check the logs after each code update.