Beginner Project: Build a Simple Discord Bot with Python

3D visualization of a friendly robot emerging from a chat window, representing a Python Discord Bot project.

Bots are awesome. With Discord Bot Python, they can moderate chat, play music, or just tell jokes. Today, we’ll build a bot that replies when you say “hello!”.

Note: You need a Discord account and your own server (it’s free to create one) to test this.

Step 1: Get Your Bot Token

  1. Go to the Discord Developer Portal.
  2. Click “New Application” and give it a name.
  3. Go to the “Bot” tab and click “Add Bot”.
  4. Copy the Token. (Keep this secret! It’s your bot’s password).

Step 2: Install the Library

pip install discord.py

Step 3: The Code

We need to connect to Discord and “listen” for messages.

import discord
from discord.ext import commands

# You must enable 'Message Content Intent' in the Developer Portal for this to work!
intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
    print(f'Bot connected as {bot.user}')

@bot.command()
async def hello(ctx):
    # 'ctx' stands for Context (info about the message)
    await ctx.send(f'Hello there, {ctx.author.name}!')

# PASTE YOUR TOKEN HERE
bot.run('YOUR_SECRET_TOKEN')

Step 4: Invite & Run

  1. Go back to the Developer Portal -> OAuth2 -> URL Generator.
  2. Check “bot” scope and “Send Messages” permission.
  3. Copy the generated URL and open it to invite the bot to your server.
  4. Run your Python script.
  5. Type !hello in your Discord server!

That’s it . you can also check out our interesting projects here —> .

Similar Posts

Leave a Reply