Updated 2 November 2026
Making your own Discord bot is easier than it sounds. In this guide you build a bot in Python with a first slash command, /ping, and then put it online 24/7. You need Python 3.10 or newer on your own computer.
1. Create the bot on Discord
- Go to the Discord Developer Portal, log in and click New Application. Give your bot a name.
- Go to Bot and click Reset Token. Copy the token. This is your bot's password: never share it.
- Go to OAuth2 → URL Generator. Under Scopes tick bot and applications.commands, and under Bot Permissions for example Send Messages.
- Open the link at the bottom in your browser and add the bot to your own server.
2. Write the code
Make a folder with three files.
requirements.txt:
discord.py
python-dotenv
.env (replace the text with your own token):
DISCORD_TOKEN=your-token-here
app.py:
import os
import discord
from discord import app_commands
from dotenv import load_dotenv
load_dotenv() # reads DISCORD_TOKEN from the .env file
intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
@tree.command(name="ping", description="Check if the bot is online")
async def ping(interaction: discord.Interaction):
await interaction.response.send_message(f"Pong! {round(client.latency * 1000)} ms")
@client.event
async def on_ready():
await tree.sync() # registers the slash commands with Discord
print(f"Logged in as {client.user}")
client.run(os.getenv("DISCORD_TOKEN"))
3. Test it on your own computer
- Install the packages:
pip install -r requirements.txt - Start the bot:
python app.py - See "Logged in as ..."? Type
/pingin your Discord server. The command can take a few minutes to appear the first time.
Close the window or turn your computer off and the bot goes offline. That's what hosting is for.
4. Put it online 24/7
With ServerSpark bot hosting your bot runs day and night, for €0.69 a month (paid quarterly):
- Order Bot hosting (Python). Your server already contains this example bot: just put your token in
.envunder Files and skip to the last step. Using your own code instead? - Upload
app.py,requirements.txtand.envin SparkPanel under Files. The server startsapp.pyby default and installs the packages fromrequirements.txtby itself. - Click Start in the Console. If the bot crashes, it's restarted automatically.
More on uploading, Git and the start file in Put your Discord bot online 24/7.
Next steps
- Add more commands by copying and changing the
@tree.commandblock. - Want to read messages (for example for a moderation bot)? Turn on the Message Content Intent under Bot in the Developer Portal, and set
intents.message_content = Truein your code. - Prefer JavaScript? Read Make a Discord bot with JavaScript.