A modern Discord bot that creates memes, engages in conversations using OpenAI, and generates Magic: The Gathering cards with AI-powered art.
- Meme Generation: React with 😂 to any message to create a meme using Imgflip API
- AI Conversations: Mention the bot or DM it for intelligent conversations powered by OpenAI
- MTG Card Creation: Use
!card <description>
to generate custom Magic: The Gathering cards with art - Mood System: Set server-specific bot personalities with
!mood <mood>
- Python 3.9+
- Discord Bot Token
- OpenAI API Key
- Imgflip Account (optional, for meme generation)
-
Clone the repository:
git clone <repository-url> cd quote-bot
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables:
cp .env.example .env
Edit
.env
and fill in your credentials:DISCORD_BOT_TOKEN
: Your Discord bot tokenOPENAI_API_KEY
: Your OpenAI API keyIMGFLIP_USERNAME
: Your Imgflip username (optional)IMGFLIP_PASSWORD
: Your Imgflip password (optional)
-
Run the bot:
python main.py
This bot is optimized for Raspberry Pi 3 and ARM processors:
-
Install Python 3.9+:
sudo apt update sudo apt install python3.9 python3.9-pip python3.9-venv
-
Create virtual environment:
python3.9 -m venv venv source venv/bin/activate
-
Install dependencies (may take longer on ARM):
pip install --upgrade pip pip install -r requirements.txt
-
Create systemd service for auto-start:
sudo nano /etc/systemd/system/quote-bot.service
Add:
[Unit] Description=Discord Quote Bot After=network.target [Service] Type=simple User=pi WorkingDirectory=/home/pi/quote-bot Environment=PATH=/home/pi/quote-bot/venv/bin ExecStart=/home/pi/quote-bot/venv/bin/python main.py Restart=always RestartSec=10 [Install] WantedBy=multi-user.target
Enable and start:
sudo systemctl enable quote-bot.service sudo systemctl start quote-bot.service
- Meme Generation: React with 😂 to any text message
- General Chat: Mention the bot (
@BotName
) or send a DM - Set Mood:
@BotName !mood <personality>
(e.g., "!mood sarcastic and witty") - Generate MTG Card:
@BotName !card <description>
(e.g., "!card a small goblin warrior")
@QuoteBot !mood friendly and helpful
@QuoteBot !card a legendary dragon that breathes fire and controls the weather
@QuoteBot What's the weather like today?
quote-bot/
├── main.py # Entry point
├── config.py # Configuration management
├── bot.py # Main Discord bot class
├── database.py # Database operations
├── meme_generator.py # Imgflip meme generation
├── openai_service.py # OpenAI API integration
├── card_formatter.py # MTG card ASCII formatting
├── tests/ # Unit tests
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
└── README.md # This file
# Install test dependencies
pip install -r requirements.txt
# Run all tests
pytest
# Run specific test file
pytest tests/test_database.py
# Run with coverage
pytest --cov=. tests/
The project follows Python best practices:
- Type hints for better code documentation
- Async/await for Discord.py compatibility
- Proper error handling and logging
- Modular design for maintainability
- Create new modules in the root directory
- Add corresponding tests in
tests/
- Update configuration in
config.py
if needed - Import and integrate in
bot.py
- Import errors: Ensure all dependencies are installed with
pip install -r requirements.txt
- Permission errors: Bot needs proper Discord permissions (Send Messages, Read Message History, Add Reactions)
- API errors: Check that API keys are valid and have sufficient credits/quota
- Database errors: Ensure write permissions in the bot directory
Check logs for debugging:
tail -f logs.log
For systemd service on Raspberry Pi:
sudo journalctl -u quote-bot.service -f
The bot requires these permissions:
- Send Messages
- Read Message History
- Add Reactions
- Use Slash Commands (future)
- Attach Files
- Embed Links
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License. See LICENSE file for details.
For issues and questions:
- Check the troubleshooting section
- Review the logs
- Create an issue on GitHub with relevant log excerpts