AI के साथ Discord बॉट कैसे बनाएं
AI-powered Discord bot आपके server को interactive और intelligent बनाता है। यह guide आपको Python और OpenAI API का उपयोग करके एक fully functional Discord bot बनाना सिखाएगी।
- Discord Developer Portal में application बनाएं. Discord Developer Portal (discord.com/developers/applications) पर जाकर 'New Application' पर click करें। Application का नाम enter करके 'Create' पर click करें। Left sidebar से 'Bot' section में जाकर 'Add Bot' button पर click करें।
- Development environment setup करें. Python 3.8+ install करें। Terminal में `pip install discord.py openai python-dotenv` command run करें। एक नया folder बनाकर उसमें `bot.py` और `.env` file create करें।
- Environment variables configure करें. .env file में `DISCORD_TOKEN=your_bot_token_here` और `OPENAI_API_KEY=your_openai_key_here` add करें। OpenAI API key के लिए platform.openai.com पर account बनाकर API key generate करें।
- Basic bot structure code करें. bot.py में Discord client import करें: `import discord from discord.ext import commands import openai import os from dotenv import load_dotenv`। Bot instance create करें: `bot = commands.Bot(command_prefix='!', intents=discord.Intents.all())`।
- AI integration implement करें. OpenAI client setup करें: `openai.api_key = os.getenv('OPENAI_API_KEY')`। AI response function बनाएं जो OpenAI API call करे और Discord message को process करे। Async function का उपयोग करके proper error handling add करें।
- Bot commands और events define करें. `@bot.event async def on_ready()` function add करें startup confirmation के लिए। `@bot.command()` decorator के साथ AI chat command बनाएं जो user input को OpenAI API को send करे और response को Discord में reply करे।
- Bot को server में invite करें. Discord Developer Portal में OAuth2 > URL Generator section में जाएं। 'bot' scope select करें और required permissions check करें। Generated URL copy करके browser में paste करें और bot को desired server में add करें।
- Bot को run करके test करें. Terminal में `python bot.py` command run करें। Discord server में `!chat Hello` type करके bot response check करें। Error logs को monitor करें और OpenAI API calls की functioning verify करें।