A Discord bot built with Go, Arikawa v3, and Uber Fx. It integrates with OpenAI's GPT models to provide intelligent chat functionalities via slash commands.
- Slash Commands: Modern Discord slash command interface
- GPT Integration: Direct integration with OpenAI's GPT models
- Thread Support: Maintains conversation context in Discord threads
- Dependency Injection: Clean architecture using Uber Fx
- Structured Logging: Comprehensive logging with Zap
- Modular Design: Extensible command and service architecture
/chat <message>- Chat with GPT and create a conversation thread/ping- Simple health check command/version- Display the current bot version
- Go 1.24.3 or later
- Docker (for containerized deployment)
- Valid Discord Bot Token and OpenAI API Key
-
Clone the repository:
git clone https://github.com/Raikerian/go-discord-chatgpt.git cd go-discord-chatgpt -
Copy the example configuration:
cp config.example.yaml config.yaml
-
Configure your
config.yamlwith:- Discord Bot Token
- Discord Application ID
- OpenAI API Key
- Guild IDs (for testing)
-
Install dependencies:
go mod download
-
Run the bot:
go run main.go
Run tests with:
go test -v ./...Run linting:
golangci-lint rungo build -o go-discord-chatgpt ./main.go# Test build (snapshot)
go tool goreleaser build --snapshot --clean
# Check configuration
go tool goreleaser checkThis project uses a complete CI/CD pipeline with GoReleaser v2 for professional release management and automated deployments.
- ✅ Runs comprehensive tests and linting
- ✅ Validates GoReleaser configuration
- ✅ Tests snapshot builds
- ✅ Reports status back to PR
- ✅ Builds snapshot version with commit SHA
- ✅ Creates multi-architecture Docker images (amd64/arm64)
- ✅ Pushes to GitHub Container Registry
- ✅ Deploys snapshot to production server
- ✅ Creates official release with GoReleaser
- ✅ Builds optimized Linux binaries
- ✅ Generates automated changelogs
- ✅ Creates GitHub release with downloadable assets
- ✅ Builds and pushes versioned Docker images
- ✅ Deploys specific version to production server
# Patch release (bug fixes)
git tag v1.0.1
git push origin v1.0.1
# Minor release (new features)
git tag v1.1.0
git push origin v1.1.0
# Major release (breaking changes)
git tag v2.0.0
git push origin v2.0.0feat: add new slash command for server management
fix: resolve memory leak in message cache
docs: update API documentation
ci: add GoReleaser configuration
chore: update dependencies# Pull and run latest version
docker pull ghcr.io/raikerian/go-discord-chatgpt:latest
docker run -d \
--name go-discord-chatgpt \
--restart unless-stopped \
-v /path/to/config.yaml:/app/config.yaml:ro \
ghcr.io/raikerian/go-discord-chatgpt:latest
# Run specific version
docker pull ghcr.io/raikerian/go-discord-chatgpt:v1.0.0
docker run -d \
--name go-discord-chatgpt \
--restart unless-stopped \
-v /path/to/config.yaml:/app/config.yaml:ro \
ghcr.io/raikerian/go-discord-chatgpt:v1.0.0# Development build
docker build -f Dockerfile -t go-discord-chatgpt:dev .
# Production build (using GoReleaser)
go tool goreleaser build --snapshot --clean
docker build -f Dockerfile.goreleaser -t go-discord-chatgpt:local .The repository includes automated deployment to DigitalOcean droplets. To set up:
Add these secrets in repository Settings → Secrets and variables → Actions:
| Secret | Description |
|---|---|
DO_HOST |
DigitalOcean droplet IP address |
DO_USERNAME |
SSH username (usually root) |
DO_SSH_PRIVATE_KEY |
SSH private key for authentication |
BOT_CONFIG |
Complete config.yaml content |
# Update system
apt update && apt upgrade -y
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
# Start and enable Docker
systemctl start docker
systemctl enable docker
# Create application directory
mkdir -p /opt/go-discord-chatgpt# Generate deployment key
ssh-keygen -t ed25519 -C "github-actions-deploy" -f ~/.ssh/github_actions_deploy
# Copy public key to server
ssh-copy-id -i ~/.ssh/github_actions_deploy.pub root@your-droplet-ip
# Copy private key content to GitHub secrets
cat ~/.ssh/github_actions_deployFor manual deployments or rollbacks:
# SSH to server
ssh root@your-droplet-ip
# Deploy specific version
cd /opt/go-discord-chatgpt
./deploy.sh v1.2.0
# Deploy latest
./deploy.sh latest
# Rollback to previous version
./deploy.sh v1.1.0# View container logs
docker logs go-discord-chatgpt
# Follow logs in real-time
docker logs -f go-discord-chatgpt# Check container status
docker ps | grep go-discord-chatgpt
# Check deployed version
docker inspect --format='{{.Config.Labels.version}}' go-discord-chatgpt
# Check deployment time
docker inspect --format='{{.Config.Labels.deployed}}' go-discord-chatgptThe Docker containers include built-in health checks:
- ✅ Process monitoring
- ✅ 30-second intervals
- ✅ Automatic restart on failure
- 🔒 Non-root container user
- 🔒 Minimal Alpine base image
- 🔒 Read-only configuration mounting
- 🔒 Key-based SSH authentication
- 🔒 GitHub Secrets for sensitive data
See config.example.yaml for a complete configuration template with all available options.
The bot uses a modular architecture with dependency injection:
- Bot Service: Core Discord event handling
- Chat Service: Orchestrates GPT interactions
- Commands: Slash command implementations
- Conversation Store: Message history management
- AI Provider: OpenAI API integration
- Cache: LRU caching for performance
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
go test -v ./...) - Commit using conventional commit format (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
The CI pipeline will automatically test your changes and provide feedback.