A Discord bot built with TypeScript that tracks PUBG (PlayerUnknown's Battlegrounds) players and provides real-time statistics and match updates. The bot monitors player matches and automatically posts updates to your Discord server.
- Real-time match tracking and monitoring
- Player statistics and performance metrics
- Automatic match updates posted to Discord channels
- MongoDB integration for data persistence
- Docker support for easy deployment
- TypeScript-based codebase with strong typing
- Comprehensive error handling and logging
- Integration and unit testing support
Before you begin, ensure you have the following installed:
- Node.js (v16 or higher)
- npm (Node Package Manager)
- MongoDB database
- Discord bot token and application
- PUBG Developer API key
- Docker and Docker Compose (optional, for containerized deployment)
- Clone the repository:
git clone https://github.com/yourusername/pubg-tracker-bot.git
cd pubg-tracker-bot
- Install dependencies:
npm install
- Build the project:
npm run build
The application requires several environment variables. You can provide them in a .env
file in the root directory or directly in your deployment configuration.
DISCORD_TOKEN=your_discord_bot_token
DISCORD_CLIENT_ID=your_discord_client_id
DISCORD_CHANNEL_ID=your_discord_channel_id
PUBG_API_KEY=your_pubg_api_key
PUBG_API_URL=https://api.pubg.com/shards/
DEFAULT_SHARD=steam
MONGODB_URI=your_mongodb_connection_string
- Never commit your
.env
file or sensitive credentials to version control. - For production, consider using Docker secrets or a secure environment variable management system.
- Discord Bot Setup:
- Go to Discord Developer Portal
- Create a new application and bot, copy the token and client ID
- Enable necessary bot permissions (Send Messages, Read Message History, etc.)
- Use the OAuth2 URL generator to invite the bot to your server
- Discord Channel ID:
- Enable Developer Mode in Discord (User Settings > Advanced)
- Right-click the desired channel and select "Copy ID"
- PUBG API Key:
- Visit PUBG Developer Portal
- Create an account and generate an API key
- Select the appropriate platform shard (e.g., 'steam')
npm run dev
npm start
- Build and start the container:
docker-compose up --build
- To run in detached mode:
docker-compose up --build -d
- To stop the container:
docker-compose down
- Build the Docker image:
docker build -t pubg-tracker-bot .
- Run the container:
docker run -d --name pubg-tracker-bot \
-e DISCORD_TOKEN=your_discord_bot_token \
-e DISCORD_CLIENT_ID=your_discord_client_id \
-e DISCORD_CHANNEL_ID=your_discord_channel_id \
-e PUBG_API_KEY=your_pubg_api_key \
-e PUBG_API_URL=https://api.pubg.com/shards/ \
-e DEFAULT_SHARD=steam \
-e MONGODB_URI=your_mongodb_connection_string \
--restart unless-stopped \
pubg-tracker-bot
- To stop and remove the container:
docker stop pubg-tracker-bot
docker rm pubg-tracker-bot
# Using Docker Compose
docker-compose logs
# Using Docker directly
docker logs pubg-tracker-bot
# To follow logs in real-time
docker-compose logs -f
docker logs -f pubg-tracker-bot
pubg-tracker-bot/
├── src/
│ ├── commands/ # Discord bot commands
│ ├── constants/ # Application constants
│ ├── data/ # Data models and repositories
│ ├── errors/ # Error handling and custom errors
│ ├── modules/ # Core application modules
│ ├── services/ # Service layer (Discord, PUBG API, etc.)
│ ├── tests/ # Test files
│ ├── types/ # TypeScript type definitions
│ ├── utils/ # Utility functions
│ └── index.ts # Main entry point
├── docker/ # Docker configuration files
├── .env # Environment variables
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker build configuration
├── package.json # Project dependencies
└── tsconfig.json # TypeScript configuration
discord.js
- Discord bot frameworkaxios
- HTTP client for API requestsmongoose
- MongoDB object modelingtypescript
- Programming languagejest
- Testing frameworkeslint
- Code lintingnodemon
- Development auto-reload
The project includes both unit and integration tests. Follow the Arrange-Act-Assert convention for unit tests and Given-When-Then for acceptance tests.
# Run unit tests
npm test
# Run integration tests
npm run test:integration
# Run tests in watch mode
npm run test:watch
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the existing issues in the GitHub repository
- Create a new issue with a detailed description of your problem
- Include relevant logs and environment details
- Never commit your
.env
file or any files containing sensitive information to version control. - Use Docker secrets or a secure environment variable management system for production deployments.
- Regularly update the Docker image and dependencies to patch security vulnerabilities.