A Discord bot that tracks team kills in online games. Admins can add/subtract TKs, and anyone can view the leaderboard.
🚀 Quick Start Guide - Get up and running in 5 minutes!
- 📊 Track team kills for server members
- 👑 Admin-only commands to add/subtract TKs
- 🏆 Public leaderboard sorted by most TKs
- 🔄 Reset functionality with safety confirmation
- 💾 Persistent storage (data survives bot restarts)
- 🎯 Role-based permissions
!showtotals- Display the team kill leaderboard!tkhelp- Show help message with all commands
!addtk @user- Add a team kill to a user!subtk @user- Subtract a team kill from a user (for corrections)!resettks- Reset all team kill data (requires confirmation)!confirmreset- Confirm the reset (must be used within 30 seconds)
Users with any of the following:
- Discord Administrator permission
- "Admin" role
- "Moderator" role (or "mod")
- "TK Manager" role
- Ruby 3.3 or higher
- A Discord account
- A Discord server where you have admin permissions
macOS:
brew install rubyUbuntu/Linux:
sudo apt-get update
sudo apt-get install ruby-fullWindows: Download from https://rubyinstaller.org/
git clone https://github.com/yourusername/discord-tk-tracker.git
cd discord-tk-trackergem install bundler
bundle installOr install gems individually:
gem install discordrb dotenv- Go to https://discord.com/developers/applications
- Click "New Application" and give it a name (e.g., "TK Tracker")
- Go to the "Bot" section in the left sidebar
- Click "Add Bot"
- Under the bot's token section, click "Reset Token" and copy the token (keep it secret!)
- Scroll down to "Privileged Gateway Intents" and enable:
- ✅ MESSAGE CONTENT INTENT
- Click "Save Changes"
-
Copy the example environment file:
cp .env.example .env
-
Edit
.envand add your bot token:DISCORD_BOT_TOKEN=your_bot_token_here
- In the Discord Developer Portal, go to "OAuth2" → "URL Generator"
- Under "Scopes", select:
- ✅ bot
- Under "Bot Permissions", select:
- ✅ Send Messages
- ✅ Read Messages/View Channels
- ✅ Read Message History
- ✅ Mention Everyone (for @mentions in responses)
- Copy the generated URL at the bottom
- Paste it in your browser and select your server
- Click "Authorize"
ruby tk_tracker_bot.rbYou should see:
Logged in as YourBotName
Bot is ready and tracking team kills!
The bot is now online! Try typing !tkhelp in your Discord server.
Just run ruby tk_tracker_bot.rb - the bot will stay online as long as the script is running.
-
Create a
Procfile:worker: ruby tk_tracker_bot.rb -
Create a
Gemfile:source 'https://rubygems.org' gem 'discordrb' gem 'dotenv'
-
Push to GitHub
-
Sign up at https://railway.app
-
Create new project from GitHub repo
-
Add environment variable:
DISCORD_BOT_TOKEN -
Deploy!
-
Create a
Procfile:worker: ruby tk_tracker_bot.rb -
Create a
Gemfile(same as above) -
Deploy:
heroku create your-bot-name heroku config:set DISCORD_BOT_TOKEN=your_token_here git push heroku main heroku ps:scale worker=1
- SSH into your server
- Install Ruby
- Clone your repository
- Install gems:
bundle install - Run with screen or tmux:
screen -S tkbot ruby tk_tracker_bot.rb # Press Ctrl+A then D to detach
Or set up as a systemd service for automatic restart.
Create a Dockerfile:
FROM ruby:3.3
RUN apt-get update && apt-get install -y ca-certificates && update-ca-certificates
WORKDIR /app
COPY Gemfile* ./
RUN bundle install
COPY . .
CMD ["ruby", "tk_tracker_bot.rb"]Build and run:
docker build -t tk-tracker-bot .
docker run -e DISCORD_BOT_TOKEN=your_token_here tk-tracker-botTeam kill data is stored in tk_data.json in the same directory as the bot. This file is automatically created and updated.
Important:
- Don't delete this file or you'll lose all TK data
- Make sure to back it up if deploying to a server
- Add it to
.gitignore(already included) to keep data local
Edit the is_admin? function in tk_tracker_bot.rb:
admin_role_names = ['Admin', 'Moderator', 'YourCustomRole']Replace ! with your preferred prefix throughout the code:
bot.message(start_with: '?addtk') do |event|Follow the existing command patterns in the code. Each command is a bot.message block.
- Make sure MESSAGE CONTENT INTENT is enabled in Discord Developer Portal
- Check that the bot has "Send Messages" permission in your server
- Verify the bot is online (should show green status)
- Check the console for error messages
If you see SSL errors on macOS, the code includes a fix that automatically uses Homebrew's certificates.
Make sure users have the correct roles or Administrator permission in Discord.
The bot only runs while the script is running. For 24/7 uptime, deploy to a hosting service (see Deployment Options).
Feel free to submit issues and pull requests!
MIT License - feel free to use and modify as needed.
For questions or issues, please open an issue on GitHub.
Built with discordrb - a Ruby Discord API library.