A Discord bot built with Python, discord.py, and OpenAI. This bot uses AI to break down feature descriptions into detailed lists of features.
- Basic Discord client setup
- OpenAI GPT-4o-mini integration
- AI-powered feature breakdown command
- Event handlers for bot ready and message events
- Environment variable configuration
- Virtual environment support
- Python 3.8 or higher
- A Discord application and bot token
- An OpenAI API key
- Go to Discord Developer Portal
- Click "New Application" and give it a name
- Go to the "Bot" section
- Click "Add Bot"
- Copy the bot token (keep this secret!)
- Go to OpenAI Platform
- Sign in or create an account
- Click "Create new secret key"
- Copy the API key (keep this secret!)
When inviting your bot to a server, make sure to give it these permissions:
- Send Messages
- Read Message History
- Use Slash Commands
- Embed Links
-
Clone or download this repository
-
Create and activate a virtual environment:
# Create virtual environment python -m venv venv # Activate virtual environment # On macOS/Linux: source venv/bin/activate # On Windows: # venv\Scripts\activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up environment variables:
cp env.example .env
-
Edit the
.envfile and add your API keys:DISCORD_TOKEN=your_actual_bot_token_here OPENAI_KEY=your_actual_openai_key_here
python feature_breakdown.pyIf everything is set up correctly, you should see a message like:
YourBotName has connected to Discord!
Bot is in X guild(s)
$breakdown <feature_description>- Use AI to break down a feature description into a detailed list of features
$breakdown Create a user authentication system
The bot will use OpenAI's GPT-4o-mini model to analyze your feature description and provide a comprehensive breakdown of the features needed.
├── feature_breakdown.py # Main bot file with OpenAI integration
├── requirements.txt # Python dependencies
├── env.example # Environment variables template
├── .env # Your actual environment variables (create this)
├── .gitignore # Git ignore file
├── venv/ # Virtual environment (created during setup)
└── README.md # This file
To add a new command, modify the on_message event handler:
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$breakdown'):
feature_description = message.content.split('$breakdown ')[1]
breakdown = call_openai(feature_description)
await message.channel.send(breakdown)
# Add your new command here
if message.content.startswith('$mycommand'):
await message.channel.send('Hello from my custom command!')To add new event handlers, use the @client.event decorator:
@client.event
async def on_member_join(member):
print(f"{member} joined the server!")Modify the command prefix in the on_message event handler:
if message.content.startswith('!'): # Change $ to ! or any other prefix
feature_description = message.content.split('!breakdown ')[1]
breakdown = call_openai(feature_description)
await message.channel.send(breakdown)To add new AI-powered functions, create new functions similar to call_openai():
def call_openai_for_analysis(text):
response = oa_client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": f"Analyze this text: {text}"}]
)
return response.choices[0].message.content- "DISCORD_TOKEN not found": Make sure you've created a
.envfile with your bot token - "OPENAI_KEY not found": Make sure you've added your OpenAI API key to the
.envfile - "Missing Permissions": Ensure your bot has the necessary permissions in the server
- "Command not found": Check that you're using the correct prefix (default is
$) - "OpenAI API Error": Verify your OpenAI API key is valid and you have credits available
- Virtual environment issues: Make sure you've activated your virtual environment before running the bot
This project is open source and available under the MIT License.