https://github.com/codergautam/worldguessr-discord-bot
https://github.com/codergautam/worldguessr-discord-bot
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/codergautam/worldguessr-discord-bot
- Owner: codergautam
- Created: 2025-09-23T00:19:19.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2025-09-23T13:59:37.000Z (8 months ago)
- Last Synced: 2025-09-23T15:37:59.977Z (8 months ago)
- Language: JavaScript
- Size: 68.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# WorldGuessr Discord Bot
A comprehensive Discord bot featuring interactive quiz systems, player statistics, and WorldGuessr game integration. Built with Discord.js v14 and SQLite.
## ๐ฏ Features
### ๐ Interactive Quiz System
- **Country TLD Quiz** - Learn country top-level domains (.com, .uk, .de, etc.)
- **Country Flag Quiz** - Identify countries by their flag emojis ๐บ๐ธ๐ฌ๐ง๐ฏ๐ต
- **Progressive Difficulty** - Starts hard, shows multiple choice after 5 wrong attempts
- **Cross-platform** - Works with both slash commands (`/`) and message commands (`!`)
- **Persistent Questions** - Questions remain until someone gets the correct answer
### ๐ Statistics & Leaderboards
- **Individual Stats** - Track your accuracy and progress per quiz category
- **Overall Leaderboards** - See top players across all quiz types
- **Category Leaderboards** - Compete in specific quiz categories
- **Detailed Analytics** - View correct/incorrect answers, accuracy percentages, attempt counts
### ๐ฎ WorldGuessr Integration
- **Player Stats Lookup** - Check any WorldGuessr player's game statistics
- **Beautiful Embeds** - Rich, formatted displays with proper styling
### ๐ ๏ธ Modular Architecture
- **Auto-detecting Commands** - Commands are automatically discovered and loaded
- **Seamless Dual Interface** - Every command works with both `/command` and `!command`
- **Generic Utilities** - Reusable components for easy development
- **Clean Code Structure** - Well-organized, maintainable codebase
## ๐ Commands
### Quiz Commands
All quiz interactions happen by simply chatting in designated quiz channels - no commands needed!
### Information Commands
| Slash Command | Message Command | Description |
|---------------|-----------------|-------------|
| `/stats [user] [category]` | `!stats` | View quiz statistics for yourself or another user |
| `/leaderboard [category] [limit]` | `!leaderboard` | View quiz leaderboards (overall, TLD, or flags) |
| `/check ` | `!check ` | Look up WorldGuessr player statistics |
| `/hello` | `!hello` | Test command to verify bot functionality |
### Command Parameters
- **category**: `tld` (Country TLD Quiz) or `flags` (Country Flag Quiz)
- **limit**: Number of users to show on leaderboard (5-25, default: 10)
- **user**: Mention another Discord user to check their stats
## ๐ Setup
### Prerequisites
- Node.js (v16 or higher)
- Discord Bot Token
- Discord Application ID
### Installation
1. **Clone the repository**
```bash
git clone
cd worldguessr-discord-bot
```
2. **Install dependencies**
```bash
npm install
```
3. **Environment Configuration**
Create a `.env` file in the root directory:
```env
DISCORD_TOKEN=your_discord_bot_token_here
CLIENT_ID=your_client_id_here
```
4. **Start the bot**
```bash
npm start
```
## ๐ค Discord Bot Setup
1. Go to the [Discord Developer Portal](https://discord.com/developers/applications)
2. Create a new application
3. Navigate to the "Bot" section and create a bot
4. Copy the bot token โ add to `.env` as `DISCORD_TOKEN`
5. Copy the Application ID โ add to `.env` as `CLIENT_ID`
6. In "OAuth2" section, generate invite link with scopes:
- `bot`
- `applications.commands`
7. Add bot permissions:
- Send Messages
- Use Slash Commands
- Embed Links
- Read Message History
- Add Reactions
8. Invite the bot to your Discord server
## ๐ฏ Quiz Setup
### Channel Configuration
The bot uses specific channel IDs for different quiz types:
- **TLD Quiz Channel**: `1419838438349344829`
- **Flags Quiz Channel**: `1420033591458398258`
To set up quiz channels in your server:
1. Create dedicated channels for each quiz type
2. Update the channel IDs in `quiz/quizManager.js` (lines 15-16)
3. Update the database categories in `database/database.js` (lines 62-63)
### How Quiz System Works
1. **Automatic Questions** - Bot posts random questions when started
2. **Community Answering** - Anyone can answer by typing in the quiz channel
3. **Progressive Difficulty**:
- Initial: Hard mode (no options)
- After 5 wrong attempts: Multiple choice (A, B, C, D, E)
4. **Answer Methods**:
- Type full country name: `"United States"`
- Type letter choice: `"A"` or `"a"`
- Alternative names accepted: `"USA"`, `"America"`, `"US"`
5. **Immediate Feedback** - Bot reacts with โ
or โ and shows correct answer
## ๐๏ธ Database
The bot uses SQLite for data persistence:
- **User Statistics** - Individual performance tracking per category
- **Quiz Categories** - Configuration for different quiz types
- **Database File** - `database/quiz_data.db` (auto-created, git-ignored)
### Database Schema
```sql
-- User quiz performance
user_stats (user_id, category, correct, incorrect, total_attempts, last_attempt)
-- Quiz category configuration
quiz_categories (category, channel_id, enabled, auto_post, description)
```
## ๐๏ธ Architecture
### File Structure
```
worldguessr-discord-bot/
โโโ commands/ # Command implementations
โ โโโ check.js # WorldGuessr player lookup
โ โโโ hello.js # Test command
โ โโโ leaderboard.js # Quiz leaderboards
โ โโโ stats.js # User statistics
โโโ database/ # Database layer
โ โโโ database.js # SQLite operations
โโโ handlers/ # Core bot handlers
โ โโโ commandHandler.js # Command loading and routing
โโโ quiz/ # Quiz system
โ โโโ quizManager.js # Quiz logic and management
โโโ utils/ # Utility functions
โ โโโ commandHandler.js # Unified command processing
โ โโโ genericUtils.js # Reusable helper functions
โโโ country_flags.json # Flag emoji mappings
โโโ country_tlds.json # TLD to country mappings
โโโ index.js # Main bot entry point
```
### Adding New Commands
Thanks to the seamless command handler system, adding new commands is incredibly easy:
```javascript
// commands/newcommand.js
const { SlashCommandBuilder } = require('discord.js');
const CommandHandler = require('../utils/commandHandler');
// Core logic - works for both slash and message commands
async function newCommandLogic({ param1, param2, isSlash }) {
// Your command logic here
const embed = new EmbedBuilder()
.setTitle('New Command')
.setDescription('Command response');
return { embed };
}
// Parameter configuration
const paramConfig = {
param1: { type: 'string', default: 'defaultValue' },
param2: { type: 'user', default: null }
};
module.exports = {
data: new SlashCommandBuilder()
.setName('newcommand')
.setDescription('Description of new command')
.addStringOption(option =>
option.setName('param1').setDescription('Parameter description')),
async execute(interaction) {
const params = CommandHandler.extractSlashParams(interaction, paramConfig);
await CommandHandler.handleCommand(newCommandLogic, params);
},
async executeMessage(message, args) {
const params = CommandHandler.extractMessageParams(message, args, paramConfig);
await CommandHandler.handleCommand(newCommandLogic, params);
}
};
```
That's it! Your command automatically supports:
- โ
Slash commands (`/newcommand`)
- โ
Message commands (`!newcommand`)
- โ
Unified error handling
- โ
Consistent response formatting
- โ
Parameter extraction
## ๐งช Development
### Available Scripts
```bash
npm start # Start the bot
npm run dev # Start the bot (development alias)
```
### Hot Reload
In development mode, send `SIGUSR2` to reload commands without restarting:
```bash
kill -SIGUSR2
```
### Git Workflow
The bot includes commit automation. When making changes:
```bash
# Changes are automatically committed with detailed messages
# Including co-authorship attribution to Claude
```
## ๐ Usage Examples
### Quiz Interaction
```
Bot: ๐ Country TLD Quiz
Which country uses the TLD: `.jp`?
Type the country name to answer!
User: Japan
Bot: โ
Correct!
Japan uses `.jp`
๐ Well done, Username!
Next question coming up...
```
### Stats Command
```
/stats user:@friend category:flags
๐ Country Flags Quiz Stats
Statistics for Friend
โ
Correct Answers: 45
โ Incorrect Answers: 12
๐ Accuracy: 78.9%
๐ฏ Total Attempts: 57
โฐ Last Attempt: 12/23/2024
```
### Leaderboard Command
```
/leaderboard category:overall limit:5
๐ Overall Quiz Leaderboard
Top 5 players by correct answers
๐ฅ TopPlayer
โ
156 correct โข โ 23 wrong โข ๐ 87.2% accuracy
๐ฅ SecondPlace
โ
134 correct โข โ 31 wrong โข ๐ 81.2% accuracy
```
## ๐ค Contributing
1. Fork the repository
2. Create your feature branch: `git checkout -b feature/amazing-feature`
3. Make your changes using the established architecture patterns
4. Test with both slash and message commands
5. Commit your changes: `git commit -m 'Add amazing feature'`
6. Push to the branch: `git push origin feature/amazing-feature`
7. Open a Pull Request
## ๐ License
ISC License - see LICENSE file for details.
## ๐ Links
- [Discord.js Documentation](https://discord.js.org/#/docs)
- [Discord Developer Portal](https://discord.com/developers/applications)
- [WorldGuessr Website](https://worldguessr.com)
---
**Built with โค๏ธ using Discord.js v14, SQLite, and modern JavaScript**