A Discord bot designed to help users track their daily calorie intake and nutritional information.
- π Track calories for different food items
- π View nutritional information
- πΈ AI-powered image recognition for food calorie estimation
- π Enhanced analysis with text descriptions for better accuracy
- π Text-only estimation for foods without images
- π€ Google Gemini Vision integration for accurate food analysis
- π¬ Interactive Discord commands
- π― Easy-to-use command system
- Python 3.8 or higher
- Discord account
- Discord server where you have permission to add bots
- Google AI Studio account (for image recognition features)
-
Clone/Download this repository
-
Set up Python virtual environment
python -m venv venv venv\Scripts\activate # On Windows # source venv/bin/activate # On macOS/Linux
-
Install dependencies
pip install -r requirements.txt
-
Create a Discord Bot
- Go to Discord Developer Portal
- Click "New Application"
- Give your bot a name
- Go to "Bot" section
- Copy the bot token
-
Configure environment variables
- Edit the
.envfile - Replace
your_bot_token_herewith your actual bot token - Get a Gemini API key from Google AI Studio
- Replace
your_gemini_api_key_herewith your actual Gemini API key
DISCORD_TOKEN=your_actual_bot_token_here COMMAND_PREFIX=! GEMINI_API_KEY=your_actual_gemini_api_key_here - Edit the
-
Invite bot to your server
- In Discord Developer Portal, go to "OAuth2" > "URL Generator"
- Select "bot" scope
- Select necessary permissions (Send Messages, Read Message History, etc.)
- Use the generated URL to invite the bot to your server
-
Run the bot
python main.py
!ping- Check if bot is responsive!info- Display bot information!addcalories <calories> [food_name]- Add calories for a food item!today- View your calories for today with numbered entries!history- View all your calorie entries for today!remove <#>- Remove a specific calorie entry by number!edit <#> <calories> [new_name]- Edit a calorie entry!reset- Reset your calories for today (with confirmation)!calorie-help- Show all calorie tracking commands!help- Show all available commands
!analyzeimage- Analyze food image for calorie estimation (attach image)!analyzefood [description]- Enhanced analysis with measurements (e.g., "350g chicken and salad")!estimate <description>- Text-only calorie estimation (no image needed)!testapi- Test if Gemini AI is working properly
After any AI analysis, the bot will add β and β reaction buttons:
- React with β to automatically add the estimated calories to your daily total
- React with β to decline adding the calories
- No need to manually type
!addcalories- just click the reaction!
Upload any food image to get:
- π₯ Calorie estimation based on visible portion
- π Nutritional breakdown (protein, carbs, fat, etc.)
- π― Confidence score for the analysis
- π Portion size estimation
- π‘ Health notes and nutritional insights
- β /β Quick add buttons via reactions
Get more accurate results by combining images with descriptions:
- Upload an image and provide measurements
- Example:
!analyzefood 350g grilled chicken breast with 2 cups rice - Higher confidence scores due to specific measurements
- Better portion size accuracy
- β /β Quick add buttons via reactions
Get calorie estimates without images:
- Perfect for homemade meals or when you can't take photos
- Example:
!estimate 1 cup oatmeal with banana and honey - Includes nutritional breakdown and health insights
!addcalories 250 Apple
!addcalories 150 Banana
!today
!reset
!ping
!info
!today
Result: Shows your total calories with numbered entries for easy reference Example Output:
π John's Calories Today
Total: 1,247 kcal
π½οΈ Recent Foods
1. 09:00 Oatmeal with berries - 180 kcal
2. 12:15 Caesar salad - 250 kcal
3. 14:30 Grilled chicken - 300 kcal
!history
Result: Shows ALL your calorie entries for today (not limited to 10)
!remove 2
Result: Removes entry #2 (Caesar salad) and updates your daily total
!edit 3 350 Grilled chicken breast
!edit 1 200
Result: Updates entry #3 to 350 calories and changes name, or just updates calories
!addcalories 300 Grilled chicken
Result: Adds 300 calories and shows your updated daily total
!reset
Result: Clears today's calories with confirmation prompt
- Upload a photo of your meal β
!analyzeimage - Get instant calorie estimate β "Grilled chicken breast: ~300 calories"
- View nutritional breakdown β Protein: 45g, Carbs: 0g, Fat: 8g
- Add to your log β React with β to add calories automatically
- Upload photo + description β
!analyzefood 350g salmon with vegetables - Get enhanced accuracy β Higher confidence due to specific measurements
- Better nutritional info β More precise calculations based on weight
- Quick logging β React with β to add to daily total
- Describe your food β
!estimate 2 slices whole wheat toast with peanut butter - Get instant estimate β "Whole wheat toast with peanut butter: ~320 calories"
- No image needed β Perfect for quick logging
CalorieCountingBot/
βββ main.py # Main bot file
βββ config.py # Configuration settings
βββ requirements.txt # Python dependencies
βββ .env # Environment variables (keep private!)
βββ .gitignore # Git ignore file
βββ README.md # This file
βββ venv/ # Virtual environment
To extend the bot with more features:
- Add new commands in
main.py - Update configuration in
config.py - Install additional dependencies in
requirements.txt
- Never commit your
.envfile to version control - Keep your Discord bot token private
- Regularly rotate your bot token if needed
-
Bot doesn't respond
- Check if bot token is correct in
.env - Ensure bot has necessary permissions in Discord server
- Check if bot is online in Discord
- Check if bot token is correct in
-
Import errors
- Make sure virtual environment is activated
- Install all dependencies:
pip install -r requirements.txt
-
Permission errors
- Ensure bot has "Send Messages" and "Read Message History" permissions
- Check channel-specific permissions
Feel free to contribute by:
- Adding new features
- Fixing bugs
- Improving documentation
- Suggesting enhancements
This project is open source and available under the MIT License.