A Discord bot that searches for cars on cars.bg and displays them with rich embeds and images.
# Clone the repository
git clone <your-repo-url>
cd bg-cars-discord-bot
# Install dependencies
go mod tidy- Create a Discord application at https://discord.com/developers/applications
- Create a bot and copy the token
- Create a
.envfile:
DISCORD_BOT_TOKEN=your_bot_token_herego run main.go| Command | Description | Example |
|---|---|---|
!cars |
Search all cars | !cars |
!cars BMW |
Search by brand | !cars BMW |
!cars BMW X5 |
Search brand + model | !cars BMW X5 |
!cars BMW X5 5 |
Search with page limit | !cars BMW X5 5 |
!help |
Show help message | !help |
!ping |
Test bot response | !ping |
bg-cars-discord-bot/
├── main.go # 🎯 Entry point (35 lines)
├── pkg/
│ ├── bot/ # 🤖 Discord bot management
│ │ └── bot.go # Connection, events, commands
│ ├── commands/ # ⚡ Bot commands
│ │ └── cars.go # Car search command
│ ├── discord/ # 💬 Discord utilities
│ │ └── embeds.go # Rich message formatting
│ └── scraper/ # 🕷️ Web scraping
│ └── scraper.go # Cars.bg scraper
├── .env # 🔐 Bot token (create this)
└── go.mod # 📦 Dependencies
- User types
!cars BMW X5in Discord - Bot receives the message
- Scraper searches cars.bg website
- Bot sends back car listings with images
Discord Message → bot.go → cars.go → scraper.go → embeds.go → Discord Response
- Create function in
pkg/commands/ - Add route in
pkg/bot/bot.go(line 95) - Update help message
- Edit
pkg/discord/embeds.go - Modify
CreateCarEmbed()function
- Edit
pkg/scraper/scraper.go - Modify
SearchCars()function
Bot not responding?
- Check your bot token in
.env - Make sure bot has message permissions
- Check console for error messages
Build errors?
go mod tidy
go mod vendor
go buildNo cars found?
- Try broader search terms
- Check if cars.bg is accessible
- Increase page limit:
!cars BMW 5
Build the project:
go buildRun with live reload:
# Install air first: go install github.com/cosmtrek/air@latest
airTest individual packages:
go test ./pkg/...- ✅ Rich Discord embeds with car images
- ✅ Bulgarian price formatting (BGN/EUR)
- ✅ Async search (doesn't block Discord)
- ✅ Error handling and fallbacks
- ✅ Clean, modular code structure
- ✅ Easy to extend with new commands
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.