NEWLoisaX CLI 1.4 and 1-command cloud deploys now liveRead post

How to host a Python Discord bot with discord.py 2.4

Python makes building Discord bots and AI integrations fast and readable. Follow these steps to package requirements.txt and main.py for reliable 24/7 hosting.

Updated Nov 15, 2026·11 min read·3 steps

What you will learn:

  • Criar e configurar sua aplicação no Discord Developer Portal.
  • Desenvolver um bot em Python com discord.py e CommandTree sincronizada.
  • Declarar dependências enxutas e fixadas no arquivo requirements.txt.
  • Configurar e proteger o DISCORD_TOKEN e logs em tempo real (PYTHONUNBUFFERED=1).
  • Preparar o pacote de código sem pastas .venv ou __pycache__.
  • Publicar e manter o bot ativo 24/7 na LoisaX.

Download the ready Python bot

Includes pinned requirements.txt and main.py with /ping and /uptime.

Step 01

Keep requirements.txt minimal and pinned

List only the packages your bot imports instead of dumping a global pip freeze:

1discord.py==2.4.0

Step 02

Set DISCORD_TOKEN and PYTHONUNBUFFERED=1

Setting PYTHONUNBUFFERED=1 ensures every print() statement flushes immediately to your live console.

Step 03

Upload without .venv or __pycache__

Local virtual environments contain OS-specific binaries. Upload only your .py files and requirements.txt.

Step 04

Got an error? The most common ones, with the fix

ModuleNotFoundError: No module named "discord"

Cause: Misspelled requirements.txt or nested outer folder inside the .zip.

Fix: Place requirements.txt directly at the project root.

Step 05

Frequently asked questions

Yes — add PyNaCl to requirements.txt for voice support.

Community & Education

Our commitment to developers

At LoisaX, we believe our role goes beyond providing hosting and cloud computing services. We also want to contribute to the learning and growth of our developer community.

We are continuously expanding our catalog of guides with new content on programming languages, API integrations, automation, and application development.

More deployment guides

All guides