Put your Discord bot online with Python (discord.py)

Run your discord.py bot 24/7: create the bot and token, set up requirements.txt and your main file, turn on intents and fix errors.

EliteStarHosting Team2 November 20264 min read

This is how you put a bot in Python with discord.py online day and night. discord.py works with Python 3.8 and newer. Your server has to run on Python for this: under Startup you then see the APP PY FILE field. Do you see MAIN FILE there instead? Then your server runs on Node.js: ask us through support to switch it. Writing in JavaScript? Then read the guide for Node.js.

1. Create your bot in Discord

  1. Go to the Discord Developer Portal, click New Application, pick a name and click Create.
  2. Open Bot, click Reset Token and copy the token. Discord shows it only once.
  3. Under Privileged Gateway Intents, turn on the intents your bot uses, see below.
  4. Open OAuth2, go to the OAuth2 URL Generator and tick bot and applications.commands. Choose under Bot Permissions what your bot may do, preferably not Administrator.
  5. Open the link at the bottom, pick your Discord server and click Authorize.

The token is your bot's password: never share it, not even with us.

2. Turn on intents

A privileged intent has to be on in the Developer Portal and in your code. If it is off in the portal, your bot won't start.

  • intents.message_content = True belongs to the Message Content Intent. You need it to read messages, such as commands with !.
  • intents.members = True belongs to the Server Members Intent, for joins, leaves and the member list.
  • intents.presences = True belongs to the Presence Intent, for online statuses.

3. Prepare your files

In requirements.txt you list the packages your bot needs, one per line:

discord.py
python-dotenv

A simple bot.py:

import os
import discord
from dotenv import load_dotenv

load_dotenv()
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)

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

client.run(os.getenv("DISCORD_TOKEN"))

.env holds a single line: DISCORD_TOKEN= followed by your token. Never share that file: this is how you keep your token safe. Never name your file discord.py, or Python loads your own file instead of the library.

4. Upload and set up Startup

  1. Upload your .py files, requirements.txt and .env through Files or SFTP. Leave out folders such as venv and __pycache__.
  2. Under Startup, fill in your main file at APP PY FILE, such as bot.py.
  3. Leave REQUIREMENTS FILE at requirements.txt: the server uses it to install your packages on every start. Single packages can also go in ADDITIONAL PYTHON PACKAGES, separated by spaces.
  4. Can you choose a Python version at Docker Image? Then take the newest.

SFTP Details with Server Address, Username and the Launch SFTP button

5. Start and fix errors

Click Start and open Console. Do you see Logged in as with your bot's name? Then it is online.

The console with the memory usage (here of a Minecraft server)

  • PrivilegedIntentsRequired: turn on the intent your code asks for in the Developer Portal.
  • Improper token has been passed.: the token is wrong. Make a new one with Reset Token.
  • received NoneType instead: your bot can't find .env or the name DISCORD_TOKEN.
  • No module named 'discord': your packages are not installed. Is requirements.txt in the main folder, and isn't it accidentally called requirements.txt.txt?
  • No module named 'audioop': your discord.py is too old for Python 3.13 or newer. Put discord.py>=2.5 in requirements.txt.

Updating

Upload your changed files and click Restart. Add new packages to requirements.txt first, then the server installs them on the restart. If your bot crashes, the panel starts it again, except after a second crash within a minute. Then read the error in the console. Restart every night? Use Schedules.