Writing a Discord bot in Python takes an evening. Keeping it online 24/7 takes a hosting plan. Below is the complete path: from creating the bot application to a working bot on the HostValues game panel.
Step 1: create the bot application
- Go to the Discord Developer Portal and click "New Application".
- Give the application a name and click "Create".
- Go to the "Bot" tab and click "Reset Token" to generate a token. Copy the token and store it safely. You only see it once.
- Under "Privileged Gateway Intents", enable: Presence Intent, Server Members Intent and Message Content Intent.
- Go to "OAuth2", select "bot" under Scopes and the permissions your bot needs under Bot Permissions (minimum: Send Messages, Read Message History).
- Copy the generated URL and open it in your browser to add the bot to your server.
Step 2: the code
Create a folder with two files:
requirements.txt
discord.py>=2.5 python-dotenv
bot.py
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
bot = commands.Bot(
command_prefix="!",
intents=discord.Intents.all()
)
@bot.event
async def on_ready():
print(f"Online as {bot.user}")
@bot.command()
async def ping(ctx):
await ctx.send(f"Pong! Latency: {round(bot.latency * 1000)}ms")
@bot.command()
async def hello(ctx):
await ctx.send(f"Hi {ctx.author.display_name}!")
bot.run(os.getenv("DISCORD_TOKEN"))
.env
DISCORD_TOKEN=your_token_here
Test locally: pip install -r requirements.txt, then python bot.py. Type !ping in your Discord server. If it works, move on to hosting.
Step 3: host on the game panel
- Order a Discord bot plan.
- Upload
bot.py,requirements.txtand.envvia the Files tab. Do not upload the__pycache__folder or a virtual environment. - In the Startup tab, set the start file to
bot.pyand choose Python 3.12. - Start the server. The panel automatically installs packages from
requirements.txt. - In the console, "Online as BotName" appears. Your bot is now available 24/7.
Adding slash commands
Slash commands are the modern way to interact with bots. They appear in the Discord menu when you type /:
@bot.tree.command(name="info", description="Shows server information")
async def info(interaction: discord.Interaction):
guild = interaction.guild
await interaction.response.send_message(
f"{guild.name} has {guild.member_count} members."
)
# Add to on_ready:
@bot.event
async def on_ready():
await bot.tree.sync()
print(f"Online as {bot.user}")
The three mistakes everyone makes
- Token in the code. Put the token in a
.envfile, not inbot.py. A token that ends up on GitHub is automatically revoked by Discord. - Intents not enabled. If you use
discord.Intents.all()but do not tick the intents in the Developer Portal, the bot starts but responds to nothing. - Forgotten requirements.txt. The panel cannot install packages if the file is missing. It works locally because you installed them manually.
See the Discord bot plans or a VPS if you run a website or database alongside the bot.
How much RAM does my bot need?
A simple command or moderation bot: under 256 MB. The smallest 1 GB plan is more than enough. A music bot on multiple servers: 2 GB.
Can I run multiple bots on one plan?
Yes. Use pm2 (npm install -g pm2) to run multiple Python scripts simultaneously. Three small bots fit in 1 GB.
discord.py or discord.js?
Python if you are new to programming: the syntax is more readable. JavaScript if you already have web experience or want to build a dashboard. Both libraries are actively maintained and equal in functionality.