Hosting Discord.py and Pycord Bots on NodeFlux | NodeFlux.eu Docs
Deploy asynchronous Python Discord bots using discord.py or Pycord with environment variable security.
Steps
- Create a main bot script (e.g., bot.py) using discord.ext.commands.
- Load bot token securely: token = os.getenv("DISCORD_TOKEN").
- Create requirements.txt file listing exact versions: discord.py>=2.3.0 or pycord.
- Upload bot.py and requirements.txt to your NodeFlux Python service container via SFTP.
- Add DISCORD_TOKEN in the service Environment Variables panel.
- Set startup command to python bot.py.
- Start service and inspect logs to confirm discord.gateway connection success.
Notes
- Always call asyncio-compatible code inside discord.py event handlers to prevent blocking the bot heartbeat.
- Intents must be explicitly declared in bot code: intents = discord.Intents.default().
Related NodeFlux pages
- Optimizing Python Memory Usage and Garbage Collection — Reduce Python RAM footprints on shared host containers by optimizing data structures and garbage collection.
- Running FastAPI and Flask Web Services with Uvicorn/Gunicorn — Deploy high-performance Python web applications and REST APIs using ASGI/WSGI production servers.
- Safeguarding Secrets and Environment Variables in Python — Keep passwords, database URIs, and API tokens out of Python source files using os.environ and python-dotenv.