Konu Değerlendirmesi:
  • 0 Oy(lar) - 0 Ortalama
  • 1
  • 2
  • 3
  • 4
  • 5
How to Build a Discord Bot in 2026 (discord.py 2.7 Guide
#1
Hello everyone,
In this guide, I’ll show you how to create a modern Discord bot from scratch using the latest 
Kod:
discord.py 2.7
 version.
We’ll build:
  • Slash command based bot
  • Modern and stable structure
  • Secure token system with 


    Kod:
    .env
  • Beginner friendly setup
  • Ready for 2026 Discord API standards

What Will You Learn?
  • Creating a Discord bot account
  • Basic bot structure
  • Slash commands (


    Kod:
    /ping



    Kod:
    /hello
    )
  • Kod:
    .env
     token security
  • Running your bot 24/7
  • Basic embeds
  • Common troubleshooting
  • Hosting methods

1. Requirements
You’ll need:
  • Python 3.10+ (recommended: Python 3.12)
  • VS Code or any text editor
  • A Discord account
Download Python:
https://python.org


2. Creating a Discord Bot Application
Go to:
https://discord.com/developers/applications
Then:
  1. Click New Application
  2. Give your bot a name
  3. Click Create
Now:
  • Open the Bot tab
  • Click Add Bot
  • Confirm
Under the Token section:
  • Click Reset Token
  • Copy your token
  • NEVER share this token publicly

3. Enable Required Intents
Inside the Bot section, enable:
  • Presence Intent
  • Server Members Intent
  • Message Content Intent
These are required for modern Discord bots in 2026.

4. Invite the Bot to Your Server
Open:
OAuth2 → URL Generator
Select:
Scopes
  • Kod:
    bot
  • Kod:
    applications.commands
Bot Permissions
For beginners, you can use:
  • Administrator
Copy the generated URL and open it in your browser.
Invite the bot to your server.

5. Project Setup
Open terminal:
Kod:
mkdir my-discord-bot
cd my-discord-bot

Create virtual environment:
Kod:
python -m venv venv

Activate it:
Windows
Kod:
venv\Scripts\activate

Linux / Mac
Kod:
source venv/bin/activate


6. Install Required Packages
Install 
Kod:
discord.py
 and 
Kod:
.env
 support:
Kod:
pip install discord.py python-dotenv

Verify installation:
Kod:
pip list


7. Creating Your First Discord Bot
Create a file called:
Kod:
main.py

Paste this code:
Kod:
import discord
from discord import app_commands
import os
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
class MyBot(discord.Client):
    def __init__(self):
        super().__init__(intents=intents)
        self.tree = app_commands.CommandTree(self)
    async def setup_hook(self):
        await self.tree.sync()
        print("Slash commands synced!")
bot = MyBot()
@bot.event
async def on_ready():
    print(f"Logged in as {bot.user}")
    await bot.change_presence(
        activity=discord.Game("/help")
    )
# Ping command
@bot.tree.command(
    name="ping",
    description="Shows bot latency"
)
async def ping(interaction: discord.Interaction):
    latency = round(bot.latency * 1000)
    await interaction.response.send_message(
        f"🏓 Pong! `{latency}ms`"
    )
# Hello command
@bot.tree.command(
    name="hello",
    description="Say hello to the bot"
)
async def hello(interaction: discord.Interaction):
    await interaction.response.send_message(
        f"Hello {interaction.user.mention}! 👋"
    )
bot.run(TOKEN)


8. Secure Your Token with .env
Create a file called:
Kod:
.env

Paste:
Kod:
DISCORD_TOKEN=YOUR_BOT_TOKEN_HERE

IMPORTANT:
Never upload this file to GitHub.

Create 
Kod:
.gitignore
:
Kod:
.env
venv/
__pycache__/


9. Run the Bot
Start the bot:
Kod:
python main.py

If everything works correctly you should see:
Kod:
Logged in as YourBotName
Slash commands synced!

Now test:
  • Kod:
    /ping
  • Kod:
    /hello
inside your Discord server.

10. Embed Command Example
Modern Discord bots use embeds heavily.
Example:
Kod:
@bot.tree.command(
    name="info",
    description="Shows bot info"
)
async def info(interaction: discord.Interaction):
    embed = discord.Embed(
        title="🤖 My Discord Bot",
        description="Modern discord.py bot for 2026",
        color=0x00ff00
    )
    embed.add_field(
        name="Latency",
        value=f"{round(bot.latency*1000)}ms"
    )
    embed.set_footer(
        text=f"Requested by {interaction.user}"
    )
    await interaction.response.send_message(
        embed=embed
    )


11. Best Free Hosting Options (2026)
Platform
Free Plan
Difficulty
NotesRailway
Yes
Easy
Best beginner option
Render
Yes
Easy
Stable free hosting
Replit
Limited
Easy
Good for testing
VPS
No
Medium
Best performance
Self-hosted
Depends
Hard
Full control


12. Running Your Bot 24/7
Railway
Probably the easiest method in 2026.
Render
Good free alternative.
VPS
Best for serious projects.
Useful commands:
Kod:
screen -S discordbot
python main.py

or use PM2:
Kod:
npm install -g pm2
pm2 start main.py --interpreter python3


13. Common Beginner Mistakes
Slash Commands Not Showing
Try:
  • reinviting the bot
  • waiting 1-2 minutes
  • syncing commands again

Invalid Token Error
Your token is wrong or expired.
Reset it inside:
Developer Portal → Bot → Reset Token


Message Content Intent Error
Enable intents inside:
Developer Portal → Bot


Bot Offline
Check:
  • internet connection
  • hosting status
  • token validity

14. Recommended Folder Structure
As your bot grows:
Kod:
my-discord-bot/

├── commands/
├── events/
├── utils/
├── .env
├── main.py
└── requirements.txt

This structure scales much better for larger bots.

15. AI Discord Bots in 2026
AI bots are huge right now.
Popular integrations:
  • OpenAI
  • Anthropic
  • Gemini
  • Groq
Use cases:
  • AI chat
  • moderation
  • ticket summaries
  • auto replies
  • server assistants
Example ideas:
  • ChatGPT Discord bot
  • AI moderation bot
  • AI support system

16. Security Tips
Never leak:
  • bot token
  • API keys
  • database passwords
Always:
  • use 


    Kod:
    .env
  • use permission checks
  • limit admin commands
  • validate user input

17. Should You Use discord.py in 2026?
Yes.
Kod:
discord.py
 is still:
  • stable
  • fast
  • actively maintained
  • beginner friendly
Best for:
  • moderation bots
  • utility bots
  • AI bots
  • automation bots

18. Final Thoughts
Discord bot development is still growing fast in 2026.
If you’re starting now, focus on:
  • Slash commands
  • Clean structure
  • Security
  • Hosting
  • Scalability
After learning the basics, you can build:
  • music bots
  • ticket systems
  • leveling systems
  • economy bots
  • AI assistants
  • moderation systems

Next Tutorials?
I can also create guides for:
  • Music Bot (Lavalink)
  • Ticket System
  • Moderation Commands
  • Leveling System
  • Economy Bot
  • AI ChatGPT Bot
  • Dashboard Panel
  • MongoDB Integration
  • PostgreSQL Setup
If you get stuck somewhere, post the error below and I’ll help.
Good luck building your Discord bot 🚀
Juniorboss
Admin


Derin Platform Yönetimi
Bul
Yanıtla


Hızlı Erişim:


Bu Konuya Göz Atan Kullanıcılar: 1 Ziyaretçi(ler)