A comprehensive Discord bot with TikTok Live integration for managing music submissions, queue prioritization, and viewer engagement tracking.
- 9-Tier Priority Queue System: 25+ Skip, 20 Skip, 15 Skip, 10 Skip, 5 Skip, Free, Pending Skips, Songs Played, Removed
- TikTok Live Integration: Real-time event tracking for gifts, joins, likes, comments, shares, follows
- Luxury Coins Economy: Earn coins via watch time (1 coin/30min) and gifts (2 coins/100 gifted coins)
- Hybrid Submission System: Slash commands, file uploads, and passive link detection
- Persistent Auto-Updating Embeds: Live queue, reviewer queue, and pending skips with 10-second refresh
- Points & Engagement Tracking: Automatic score calculation for Free queue ordering
- Admin Tools: Force link/unlink TikTok handles, metrics reporting, channel configuration
- Python 3.10+
- PostgreSQL database
- Discord Bot Token
- Clone the repository and install dependencies:
pip install -r requirements.txt- Configure environment variables:
cp .env.example .envEdit .env and add your Discord bot token:
DISCORD_BOT_TOKEN=your_bot_token_here
DATABASE_URL=postgresql://user:password@localhost:5432/music_bot
ALLOW_ANY_HANDLE_LINKING=false
- Run the bot:
python main.pyThe bot automatically creates all required tables and indexes on first run:
live_sessions- TikTok live stream sessionstiktok_accounts- TikTok user handles and pointstiktok_interactions- Event tracking (gifts, joins, likes, etc.)viewer_count_snapshots- Viewer count trackingsubmissions- Music submissionsuser_points- Discord user engagement pointsbot_config- Bot configurationpersistent_embeds- Auto-updating embed trackingqueue_config- Queue channel configurationluxury_coins- Luxury Coins economytiktok_watch_time- Watch time tracking for coin rewards
/submit- Submit a music link (YouTube, Spotify, SoundCloud, Deezer, Ditto)/submitfile- Submit a music file (mp3, m4a, wav, flac - max 25MB)/queue [page]- View the current queue/link-tiktok <handle>- Link your TikTok handle/unlink-tiktok <handle>- Unlink a TikTok handle/my-links- View your linked TikTok handles/coins- Check your Luxury Coins balance/buy-skip- Spend 1000 Luxury Coins to move submission to 10 Skip tier/leaderboard-coins- View Luxury Coins leaderboard
/next- Play the next song in queue (resets points for Free tier)/remove-submission <id>- Remove a submission from queue/set-submission-channel <#channel>- Configure submissions-only channel/setup-live-queue <#channel>- Setup live queue embed/setup-reviewer-channel <#channel>- Setup reviewer embeds with approve/remove buttons/set-metrics-channel <#channel>- Set metrics reporting channel/post-live-metrics- Post metrics for last live session/admin-link <@user> <handle>- Force link TikTok handle to user/admin-unlink <@user> <handle>- Force unlink TikTok handle/admin-give-coins <@user> <amount>- Give Luxury Coins to user
/tiktok-connect <username> [persistent=true]- Connect to TikTok live stream/tiktok-status- Check connection status/tiktok-disconnect- Disconnect from live stream
- 25+ Skip (≥6000 coins) - Highest priority, FIFO
- 20 Skip (5000-5999 coins)
- 15 Skip (4000-4999 coins)
- 10 Skip (2000-3999 coins)
- 5 Skip (1000-1999 coins)
- Free - Sorted by engagement points (DESC), then submission time (ASC)
- Pending Skips - Admin review required
- Songs Played - Archive
- Removed - Deleted by admin
- Configure submissions channel with
/set-submission-channel - Passive submissions (links/files) only accepted in configured channel
- Submissions in other channels are deleted with error message
- YouTube
- Spotify
- SoundCloud
- Deezer
- Ditto
- Apple Music
- iTunes
- Supported formats: mp3, m4a, wav, flac
- Maximum size: 25MB
- Auto-uploaded to Discord CDN
All TikTok Live events are tracked:
- JoinEvent
- LikeEvent
- CommentEvent
- ShareEvent
- FollowEvent
- SubscribeEvent
- GiftEvent (with streak detection)
- RoomUserSeqEvent
- ViewerCountUpdateEvent
- ConnectEvent
- DisconnectEvent
- LiveEndEvent
Points calculation:
- If diamond_count < 1000:
points = diamond_count * 2 - Else:
points = diamond_count
Skip tier determination:
- ≥6000 coins → 25+ Skip
- ≥5000 coins → 20 Skip
- ≥4000 coins → 15 Skip
- ≥2000 coins → 10 Skip
- ≥1000 coins → 5 Skip
- Watch Time: 1 coin per 30 minutes watched (requires linked TikTok handle)
- Gifts: 2 coins per 100 gifted coins
- Buy Skip: 1000 coins moves submission from Free/Pending Skips/5 Skip to 10 Skip tier
- Updates every 10 seconds
- 1-second delay between embed updates to avoid rate limits
- Content-hash optimization skips unchanged content
- Self-healing: recreates deleted messages
- Live Queue - Public view with pagination and emoji indicators
- Reviewer Main Queue - Admin view with approve/remove buttons
- Reviewer Pending Skips - Awaiting admin approval
- Discord user points (
user_pointstable) - TikTok handle points (
tiktok_accountstable) - Points sync to linked Discord users
- TikTok event awards points to handle
- If linked to Discord user, points added to
user_points sync_submission_scores()runs every 30 seconds- Updates
submissions.total_scorefor Free queue ordering - When Free-line song plays, submitter's points reset to 0
- Hourly JSON backups of
user_pointsandtiktok_accounts - Stored in
backups/directory with timestamps - Automatic cleanup: keeps last 48 backups (2 days)
.
├── main.py # Bot entry point
├── database.py # Database schema and connection pool
├── requirements.txt # Python dependencies
├── .env # Environment configuration
├── cogs/
│ ├── submissions.py # Submission commands and passive detection
│ ├── queue.py # Queue management and /next command
│ ├── tiktok_integration.py # TikTok Live connection and events
│ ├── tiktok_linking.py # Handle linking commands
│ ├── luxury_coins.py # Coins economy system
│ ├── persistent_embeds.py # Auto-updating embeds
│ ├── admin.py # Admin commands
│ └── points_sync.py # Points sync and backups
├── tests/
│ └── test_bot.py # Unit tests
└── backups/ # Hourly JSON backups
- Full async/await implementation
- AsyncPG connection pooling
- Background tasks for:
- Embed refresh (10s loop)
- Points sync (30s loop)
- Watch time tracking (1min loop)
- Hourly backups
- Comprehensive try/except blocks
- Logging throughout all cogs
- Self-healing embeds on deletion
- Transaction rollback on failures
python -m pytest tests/- PEP8 compliant
- Parameterized SQL queries (SQL injection safe)
- Type hints where applicable
- Comprehensive logging
- Set up PostgreSQL database
- Configure environment variables
- Run bot with
python main.py - Configure channels with admin commands
- Connect to TikTok live stream
- Start accepting submissions!
MIT License