🌐 Detecting your location…
📢 Advertisement — Configure AdSense in Appearance → Customize → AdSense Settings

2026 में पायथन के साथ एक डिसॉर्डर बॉट कैसे बनाएं: संपूर्ण ट्यूटोरियल

⏱️3 min read  ·  521 words

एक निर्माणकलह बॉट एक मज़ेदार, व्यावहारिक पायथन प्रोजेक्ट है जो एसिंक प्रोग्रामिंग, एपीआई और इवेंट हैंडलिंग सिखाता है। 2026 में,discord.py इसे सीधा बनाता है. यह मार्गदर्शिका स्लैश कमांड, एंबेड और इंटरैक्टिव बटन के साथ एक कार्यात्मक बॉट बनाती है, फिर उसे तैनात करती है।

चरण 1: एक डिसॉर्डर एप्लिकेशन बनाएं

  1. डिस्कॉर्ड डेवलपर पोर्टल (discord.com/developers)
  2. पर जाएं क्लिक करेंनया एप्लीकेशन, अपने बॉट को नाम दें
  3. पर जाएँ बॉट अनुभाग, क्लिक करेंबॉट जोड़ेंकॉपी करें
  4. टोकन (इसे गुप्त रखें – ऐसा कभी न करें)सक्षम करें
  5. संदेश सामग्री आशय विशेषाधिकार प्राप्त गेटवे इरादों के तहतके अंतर्गत
  6. OAuth2, फिर URL जेनरेटर: चुनें औरbot स्कोप, अनुमतियाँ चुनें, और बॉट को अपने सर्वर पर आमंत्रित करने के लिए जेनरेट किए गए URL का उपयोग करेंapplications.commandsचरण 2: सेटअप

चरण 3: स्लैश कमांड के साथ बेसिक बॉट

pip install discord.py python-dotenv

# Project structure
mybot/
├── bot.py
├── .env
└── requirements.txt
# .env — never commit this
DISCORD_TOKEN=your_bot_token_here

चरण 4: रिच एंबेड्स

# bot.py
import os
import discord
from discord import app_commands
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()

intents = discord.Intents.default()
intents.message_content = True

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

@bot.event
async def on_ready():
    # Sync slash commands with Discord
    await bot.tree.sync()
    print(f"Logged in as {bot.user}")

# Slash command
@bot.tree.command(name="hello", description="Greet the user")
async def hello(interaction: discord.Interaction):
    await interaction.response.send_message(
        f"Hello, {interaction.user.mention}!"
    )

# Slash command with parameters
@bot.tree.command(name="add", description="Add two numbers")
async def add(interaction: discord.Interaction, a: int, b: int):
    await interaction.response.send_message(f"{a} + {b} = {a + b}")

bot.run(os.getenv("DISCORD_TOKEN"))

चरण 5: इंटरैक्टिव बटन

@bot.tree.command(name="userinfo", description="Show user information")
async def userinfo(interaction: discord.Interaction, member: discord.Member = None):
    member = member or interaction.user

    embed = discord.Embed(
        title=f"User Info: {member.display_name}",
        color=discord.Color.blurple()
    )
    embed.set_thumbnail(url=member.display_avatar.url)
    embed.add_field(name="Username", value=str(member), inline=True)
    embed.add_field(name="ID", value=member.id, inline=True)
    embed.add_field(
        name="Joined",
        value=member.joined_at.strftime("%Y-%m-%d"),
        inline=False
    )
    embed.set_footer(text="MyBot")

    await interaction.response.send_message(embed=embed)

चरण 6: इवेंट हैंडलिंग

class ConfirmView(discord.ui.View):
    def __init__(self):
        super().__init__(timeout=60)
        self.value = None

    @discord.ui.button(label="Confirm", style=discord.ButtonStyle.green)
    async def confirm(self, interaction: discord.Interaction, button: discord.ui.Button):
        self.value = True
        await interaction.response.send_message("Confirmed!", ephemeral=True)
        self.stop()

    @discord.ui.button(label="Cancel", style=discord.ButtonStyle.red)
    async def cancel(self, interaction: discord.Interaction, button: discord.ui.Button):
        self.value = False
        await interaction.response.send_message("Cancelled.", ephemeral=True)
        self.stop()

@bot.tree.command(name="confirm", description="Ask for confirmation")
async def confirm_cmd(interaction: discord.Interaction):
    view = ConfirmView()
    await interaction.response.send_message("Are you sure?", view=view)

चरण 7: बॉट तैनात करें

# Welcome new members
@bot.event
async def on_member_join(member):
    channel = member.guild.system_channel
    if channel:
        await channel.send(f"Welcome {member.mention} to the server!")

# React to messages
@bot.event
async def on_message(message):
    if message.author == bot.user:
        return  # ignore the bot's own messages

    if "hello bot" in message.content.lower():
        await message.channel.send("Hello there!")

    await bot.process_commands(message)  # keep prefix commands working

अक्सर पूछे जाने वाले प्रश्न

# Bots need to run 24/7. Deploy to a small VPS or Railway/Fly.io.

# On a VPS with systemd — /etc/systemd/system/mybot.service
[Unit]
Description=Discord Bot
After=network.target

[Service]
WorkingDirectory=/opt/mybot
ExecStart=/opt/mybot/venv/bin/python bot.py
Restart=always
EnvironmentFile=/opt/mybot/.env

[Install]
WantedBy=multi-user.target

# Enable and start
sudo systemctl enable mybot
sudo systemctl start mybot

प्रश्न: स्लैश कमांड बनाम प्रीफ़िक्स कमांड?

उत्तर: स्लैश कमांड (
) आधुनिक मानक हैं – डिस्कॉर्ड उन्हें पैरामीटर संकेत वाले मेनू में दिखाता है। उपसर्ग आदेश (/command) अभी भी काम करते हैं लेकिन विरासत हैं। नए बॉट के लिए स्लैश कमांड का उपयोग करें।!commandप्रश्न: मेरे स्लैश कमांड दिखाई क्यों नहीं दे रहे हैं?

उत्तर: आपको अवश्य कॉल करना चाहिए
उन्हें डिस्कॉर्ड के साथ पंजीकृत करने के लिए (ऊपर on_ready में किया गया)। वैश्विक सिंक को प्रसारित होने में एक घंटे तक का समय लग सकता है; त्वरित परीक्षण के लिए एक विशिष्ट गिल्ड के साथ सिंक करें।bot.tree.sync()प्रश्न: मैं अपने बॉट टोकन को कैसे सुरक्षित रखूँ?

ए: इसे
में स्टोर करें फ़ाइल (gitignored), इसे कभी भी हार्डकोड न करें, और इसे कभी भी प्रतिबद्ध न करें। यदि लीक हो गया है, तो इसे तुरंत डेवलपर पोर्टल में पुन: उत्पन्न करें – एक लीक टोकन किसी को भी आपके बॉट को नियंत्रित करने देता है।.envप्रश्न: मुझे अपने बॉट को मुफ़्त/सस्ते में कहाँ होस्ट करना चाहिए?

उत्तर: रेलवे और Fly.io के पास निःशुल्क/कम लागत वाले स्तर हैं। सिस्टमडी के साथ $4-6/माह का वीपीएस (हेट्ज़नर, कॉन्टैबो) विश्वसनीय और सस्ता है। उन मुक्त स्तरों से बचें जो निष्क्रियता पर सोते हैं – बॉट्स को लगातार चलने की आवश्यकता होती है।
प्रश्न: मैं अपने बॉट में डेटाबेस कैसे जोड़ूँ?

ए: सरल बॉट्स के लिए SQLite (async के लिए aiosqlite के माध्यम से), या बड़े बॉट्स के लिए PostgreSQL (asyncpg)। प्रति-सर्वर सेटिंग्स, उपयोगकर्ता डेटा, या कमांड स्थिति संग्रहीत करें। बॉट को ब्लॉक करने से बचने के लिए हमेशा एसिंक डेटाबेस लाइब्रेरीज़ का उपयोग करें।
निष्कर्ष

पायथन के साथ डिस्कोर्ड बॉट बनाना एक सुलभ प्रोजेक्ट है जो एसिंक प्रोग्रामिंग और एपीआई एकीकरण सिखाता है।

लाइब्रेरी कठिन भागों को संभालती है – आप स्लैश कमांड, रिच एंबेड और स्वच्छ डेकोरेटर के साथ इंटरैक्टिव बटन को परिभाषित करते हैं। एक बार जब आपका बॉट स्थानीय रूप से काम करने लगे, तो इसे सिस्टमडी (या रेलवे/फ्लाई.आईओ) के साथ एक छोटे वीपीएस पर तैनात करें ताकि यह 24/7 चले। यहां से, अपने बॉट को आपके समुदाय की आवश्यकतानुसार विकसित करने के लिए एक डेटाबेस, अधिक कमांड और ईवेंट हैंडलर जोड़ें।discord.py लाइब्रेरी कठिन भागों को संभालती है – आप स्लैश कमांड, रिच एंबेड और स्वच्छ डेकोरेटर के साथ इंटरैक्टिव बटन को परिभाषित करते हैं। एक बार जब आपका बॉट स्थानीय रूप से काम करने लगे, तो इसे सिस्टमडी (या रेलवे/फ्लाई.आईओ) के साथ एक छोटे वीपीएस पर तैनात करें ताकि यह 24/7 चले। यहां से, अपने बॉट को आपके समुदाय की आवश्यकतानुसार विकसित करने के लिए एक डेटाबेस, अधिक कमांड और ईवेंट हैंडलर जोड़ें।

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *

🌐 Read in:🇩🇪 Deutsch🇧🇷 Português🇸🇦 العربية🇮🇳 हिन्दी🇧🇩 বাংলা