How to Make a Discord Bot: Beginner’s Guide
By Shah Rukh, software developer · Last updated:
A Discord bot is a small program that logs in to Discord like a member and responds to commands and events: welcoming people, moderating chat, running polls and more. This guide walks you through making one from scratch, even if you’ve never coded.
What you need
- A Discord account and a server where you have Manage Server permission. (Make a free test server if you like.)
- A computer with Python 3.10 or newer.
- About 15 minutes.
Step 1: Create the application
- Go to the Discord Developer Portal and log in.
- Click New Application, type a name and create it.
- On General Information, copy the Application ID. You’ll need it for the invite link.
Step 2: Get your bot token
- Open the Bot tab.
- Click Reset Token, then Copy.
The token is your bot’s password. Never share it or post it online. If it leaks, reset it straight away.
Step 3: Turn on the intents you need
Intents tell Discord which events your bot wants to receive. On the Bot tab, under Privileged Gateway Intents:
- Server Members Intent: needed for welcome messages and auto-roles.
- Message Content Intent: needed only if the bot reads normal messages, for example a word filter. Slash commands don’t need it.
Step 4: Get the code
The quickest way is the Discord bot maker: tick the features you want and download a ready-to-run project. Or start with this minimal bot in a file called bot.py:
import os
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix=commands.when_mentioned, intents=discord.Intents.default())
@bot.event
async def on_ready():
await bot.tree.sync()
print(f"Logged in as {bot.user}")
@bot.tree.command(description="Say hello")
async def hello(interaction: discord.Interaction):
await interaction.response.send_message(f"Hello, {interaction.user.mention}!")
bot.run(os.environ["DISCORD_TOKEN"])
Install the library with python -m pip install discord.py.
Step 5: Invite the bot to your server
Open this link, with your Application ID in place of the capitals:
https://discord.com/oauth2/authorize?client_id=YOUR_APPLICATION_ID&scope=bot+applications.commands&permissions=85056
Pick your server and click Authorize. The applications.commands part is what allows slash commands.
Step 6: Run it
Set your token and start the bot. With a project from the bot maker, put the token in the .env file and double-click start.bat. When you see “Logged in as…”, type / in your server and try a command.
Common problems
| Problem | Fix |
|---|---|
| Slash commands don’t appear | Wait up to an hour for global commands, or sync to one server for instant updates. Check you invited the bot with applications.commands. |
| “Improper token” error | Copy the token again from the Bot tab; make sure there are no spaces or quotes around it. |
| “Privileged intents” error | Turn on the intents from Step 3 and save. |
| Bot can’t kick, ban or give roles | Drag the bot’s role above the roles it manages in Server Settings → Roles. |
| Bot goes offline | It only runs while the program is open. Host it on a server to keep it online. |
Rules to follow
Bots must follow Discord’s Terms of Service and Developer Policy. In short: don’t spam, don’t send unsolicited mass DMs, don’t collect members’ data without telling them, and don’t automate normal user accounts (“self-bots”).
Want your exact number? Use the free Discord Bot Maker. It takes about 30 seconds.
Frequently asked questions
Is making a Discord bot free?
Yes. Creating a bot and using Discord’s API is free. You only pay if you choose paid hosting to keep it online all the time.
Which language is best for Discord bots?
Python (discord.py) and JavaScript (discord.js) are the two most popular. Python is usually easier for beginners.
Can I make a bot on my phone?
You can create the application on a phone, but running the bot needs a computer or server.
How do I keep my bot online 24/7?
Run it on a machine that’s always on, such as a cloud server or a Raspberry Pi.