Skip to content

Lantern Discord Bot - Complete Guide โ€‹

Standalone Discord bot for submitting feature requests and bug reports directly from Discord.

Status: โœ… Production Ready
Location: discord-bot/
Source: bot.js, register-commands.js


Table of Contents โ€‹

  1. Overview
  2. Features
  3. Architecture
  4. Environments
  5. Setup Instructions
  6. Local Testing
  7. Deployment
  8. Usage
  9. GitHub Integration
  10. Troubleshooting
  11. Monitoring & Maintenance

Overview โ€‹

The Discord bot enables team members and users to submit feature requests and bug reports using Discord slash commands. All submissions automatically:

  • Create GitHub issues with proper labels
  • Post to public Discord channels (#features or #bugs)
  • Notify admin team in private channel
  • Store data in Firestore for tracking
  • Integrate with GitHub Projects V2

Core Commands:

  • /feature - Submit a feature request
  • /bug - Report a bug
  • /mystatus - Check status of your submissions

Auto-Features:

  • Smart auto-prompts for regular messages
  • Multi-environment support (local, staging, production)
  • Rate limiting to prevent spam
  • Full audit trail in Firestore

Features โ€‹

Smart Auto-Prompts โ€‹

When users post a regular message in #features or #bugs (without using slash commands), the bot automatically:

  1. Detects the message in submission channels
  2. Replies with a helpful prompt explaining how to use the slash command
  3. Shows benefits of using structured forms
  4. Provides "Got it!" button to dismiss
  5. Auto-deletes after 30 seconds to keep channels clean

Example:

User: "The app crashes when I click the profile button"

Bot: ๐Ÿ’ก Quick Tip: Use /bug to submit
Hey @user! To submit a bug report, use the /bug slash command.

Why use slash commands?
โœ… Structured form with all required details
โœ… Automatic GitHub issue creation
โœ… Tracked in our system
โœ… You can check status with /mystatus

[Got it! button]

Command Discovery โ€‹

Users discover commands by:

  1. Typing / in Discord (autocomplete shows available commands)
  2. Reading pinned messages in #features and #bugs
  3. Checking channel topic descriptions

Architecture โ€‹

Discord User
    โ†“
/feature or /bug command
    โ†“
Modal Form (Discord native)
    โ†“
Bot validates input
    โ†“
Creates GitHub issue + Firestore record
    โ†“
Posts to #features or #bugs
    โ†“
Notifies #admin-monitor
    โ†“
User receives confirmation with GitHub link

Key Components:

  • bot.js - Main bot logic and command handlers
  • register-commands.js - Slash command registration
  • Discord.js - Bot framework
  • Firebase Admin SDK - Firestore integration
  • Octokit - GitHub API integration

Environments โ€‹

EnvironmentPurposeGuild IDDatabaseLocationConfig
Local TestingDev & feature testingTest guild (separate)Dev databaseYour machine.env.testing
Dev DeployedStaging/QADev guildDev databaseRailwayRailway vars
ProductionLive usersProd guildProd databaseRailwayRailway vars

Important: Each environment uses a separate Discord bot application and Firestore database.


Setup Instructions โ€‹

Step 1: Create Discord Application โ€‹

  1. Go to Discord Developer Portal
  2. Click "New Application"
  3. Name it "Lantern Bot"
  4. Go to "Bot" tab โ†’ Click "Add Bot"
  5. Under "Privileged Gateway Intents", enable:
    • โœ… Message Content Intent (required for auto-prompts)
    • โœ… Server Members Intent
    • โœ… Presence Intent
  6. Click "Reset Token" โ†’ Copy and save securely

Step 2: Configure OAuth2 Scopes & Permissions โ€‹

  1. Go to "OAuth2" โ†’ "URL Generator"
  2. Select scopes:
    • โœ… bot
    • โœ… applications.commands
  3. Select bot permissions:
    • โœ… Send Messages
    • โœ… Embed Links
    • โœ… Read Message History
    • โœ… Use Slash Commands
    • โœ… Manage Messages (for auto-prompts)
  4. Copy generated URL
  5. Open URL in browser โ†’ Select your server โ†’ Authorize

Step 3: Get Discord IDs โ€‹

Enable Developer Mode:

  1. Discord โ†’ User Settings โ†’ Advanced
  2. Enable "Developer Mode"

Get IDs by right-clicking:

  • Server name โ†’ "Copy Server ID" โ†’ DISCORD_GUILD_ID
  • #features channel โ†’ "Copy ID" โ†’ DISCORD_FEATURE_CHANNEL_ID
  • #bugs channel โ†’ "Copy ID" โ†’ DISCORD_BUG_CHANNEL_ID
  • #admin-monitor channel โ†’ "Copy ID" โ†’ DISCORD_ADMIN_MONITOR_CHANNEL_ID

Step 4: Install Dependencies โ€‹

bash
cd discord-bot
npm install

Dependencies:

  • discord.js - Discord bot framework
  • firebase-admin - Firestore access
  • @octokit/rest - GitHub API
  • dotenv - Environment variable loading

Step 5: Configure Environment Variables โ€‹

For Local Development:

bash
cp .env.testing .env

Edit .env with your values:

bash
# Discord Configuration
DISCORD_BOT_TOKEN=your_bot_token_here
DISCORD_CLIENT_ID=your_application_id_here
DISCORD_GUILD_ID=your_server_id_here

# Discord Channel IDs
DISCORD_FEATURE_CHANNEL_ID=123456789012345678
DISCORD_BUG_CHANNEL_ID=123456789012345678
DISCORD_ADMIN_MONITOR_CHANNEL_ID=123456789012345678

# Firebase
FIREBASE_PROJECT_ID=lantern-app-dev

# GitHub
GITHUB_TOKEN=ghp_your_github_personal_access_token
GITHUB_REPO=cattreedev/lantern_app

# GitHub Project V2 (Optional - defaults provided)
GITHUB_PROJECT_NAME=Lantern App
GITHUB_MILESTONE_NAME=Prototype

Step 6: Firebase Service Account Setup (Choose One Method) โ€‹

Method 1: File Path (Recommended for Local)

  1. Go to Firebase Console โ†’ lantern-app-dev project
  2. Project Settings โ†’ Service Accounts โ†’ "Generate New Private Key"
  3. Save to ~/repos/secrets/firebase/lantern-app-dev-firebase-adminsdk-*.json
  4. Add to .env:
    bash
    FIREBASE_SERVICE_ACCOUNT_PATH=~/repos/secrets/firebase/lantern-app-dev-firebase-adminsdk-*.json

Method 2: JSON String (Recommended for Deployment)

  1. Get service account JSON (same as above)
  2. Add to environment variables:
    bash
    FIREBASE_SERVICE_ACCOUNT_KEY='{"type":"service_account","project_id":"lantern-app-dev",...}'

The bot uses FIREBASE_SERVICE_ACCOUNT_KEY if available, otherwise falls back to file path.

โš ๏ธ Never commit these files to Git! They're in .gitignore.

Step 7: Register Slash Commands โ€‹

โš ๏ธ Critical: Must be done BEFORE commands work in Discord (one-time setup).

bash
npm run register

Expected output:

Registering commands...
Successfully registered 3 application commands.

After this, /feature, /bug, and /mystatus will appear in Discord.


Local Testing โ€‹

Testing Setup โ€‹

For testing features locally without affecting production:

  1. Create a separate test Discord server (or use existing test server)
  2. Invite the bot to your test server
  3. Create test channels (#features, #bugs, #admin-monitor)
  4. Get test channel IDs and update .env.testing
  5. Run locally with isolated test configuration

Testing Workflow โ€‹

bash
cd discord-bot

# Use test configuration
cp .env.testing .env

# Install dependencies (if first time)
npm install

# Register slash commands (one-time)
npm run register

# Run bot locally
npm start

# In a separate terminal, test by running Discord commands
# When done, stop with Ctrl+C

What Happens During Local Testing โ€‹

  • โœ… Bot connects to test Discord guild (separate server)
  • โœ… Issues created in GitHub go to Lantern App Testing project
  • โœ… All data uses dev Firebase database (no production data touched)
  • โœ… Milestones tagged with Testing label
  • โœ… Production bot and guilds completely unaffected

Testing Checklist โ€‹

After deployment, test:

  1. Slash Commands

    • Type / in any channel
    • See /feature, /bug, /mystatus
    • Run /feature and fill out modal
    • Submit
  2. Verify Results

    • โœ… Message posted in #features channel
    • โœ… Notification in #admin-monitor channel
    • โœ… GitHub issue created with correct labels
    • โœ… Firestore document created
  3. Test Auto-Prompts

    • Post a regular message in #features or #bugs
    • Bot should reply with helpful prompt
    • Click "Got it!" or wait 30 seconds
    • Message should auto-delete
  4. Test /mystatus

    • Run /mystatus command
    • Should show your submission history

Deployment โ€‹

Option A: Local Testing (Quick Start) โ€‹

bash
npm start
  • โœ… Immediate, no cost, easy debugging
  • โŒ Must keep computer on, not production-ready

Railway is a platform-as-a-service with generous free tier.

Setup Steps โ€‹

  1. Create Account

  2. Create New Project

    • Click "New Project" โ†’ "Empty Project"
    • Name it "lantern-discord-bot"
  3. Deploy from GitHub

    • In Railway project โ†’ "New" โ†’ "GitHub Repo"
    • Select cattreedev/lantern_app
    • Set root directory: discord-bot
  4. Add Environment Variables In Railway dashboard โ†’ Variables:

    DISCORD_BOT_TOKEN=your_token
    DISCORD_CLIENT_ID=your_client_id
    DISCORD_GUILD_ID=your_guild_id
    DISCORD_FEATURE_CHANNEL_ID=123...
    DISCORD_BUG_CHANNEL_ID=123...
    DISCORD_ADMIN_MONITOR_CHANNEL_ID=123...
    FIREBASE_PROJECT_ID=lantern-app-dev
    FIREBASE_SERVICE_ACCOUNT_PATH=/app/service-account.json
    GITHUB_TOKEN=ghp_...
    GITHUB_REPO=cattreedev/lantern_app
    GITHUB_PROJECT_NAME=Lantern App
    GITHUB_MILESTONE_NAME=Prototype
  5. Upload Service Account

    • Railway โ†’ Settings โ†’ Add Secret File
    • Name: service-account.json
    • Upload Firebase service account JSON
    • Path: /app/service-account.json
  6. Deploy

    • Railway auto-deploys. Monitor logs in dashboard.

Cost: Free tier gives 500 hours/month (sufficient for 24/7 bot). After: ~$5/month.

Option C: Self-Hosted Server (Advanced) โ€‹

If you have a VPS or cloud VM:

bash
# On your server
git clone https://github.com/cattreedev/lantern_app.git
cd lantern_app/discord-bot
npm install

# Copy service account
scp ~/repos/secrets/firebase/lantern-app-dev-service-account.json \
    user@server:/path/to/lantern_app/discord-bot/

# Create .env file
nano .env  # paste environment variables

# Run with PM2 (keeps bot alive)
npm install -g pm2
pm2 start bot.js --name lantern-bot
pm2 save
pm2 startup  # enables autostart on reboot

Option D: Heroku (Alternative) โ€‹

bash
heroku create lantern-discord-bot
heroku config:set DISCORD_BOT_TOKEN=xxx
heroku config:set FIREBASE_PROJECT_ID=lantern-app-dev
# ... set all other vars
git push heroku main

Note: Heroku no longer offers free tier. Railway or self-hosting recommended.


Usage โ€‹

Submit a Feature Request โ€‹

/feature

Modal fields:

  • Title (required, max 100 chars)
  • Description (required, max 1000 chars)
  • Use Case (optional, max 500 chars)
  • Priority (low/medium/high/critical)
  • Impact (individual/small-group/all-users)

Report a Bug โ€‹

/bug

Same modal as feature requests, posted to #bugs channel instead.

Check Your Submissions โ€‹

/mystatus

Shows your recent submissions with current status and GitHub links.

What Happens When You Submit โ€‹

  1. Modal submission โ†’ Bot validates input
  2. GitHub issue created โ†’ Automatically formatted with labels
  3. Public channel post โ†’ Appears in #features or #bugs
  4. Admin notification โ†’ Posted to #admin-monitor (private)
  5. User confirmation โ†’ You receive:
    • Direct link to your submission
    • Link to browse all issues
    • Tip about using /mystatus

Channel Setup Guidance โ€‹

#features Channel

Topic:

๐Ÿ’ก Submit feature ideas using /feature command

Pinned message:

Welcome to #features! ๐ŸŒŸ

Have an idea to improve Lantern? Submit it here!

**How to submit:**
1. Type `/feature` anywhere in this channel
2. Fill out the form that appears
3. Your request will be posted here and tracked on GitHub

**Need help?** Type `/mystatus` to see your submissions

#bugs Channel

Topic:

๐Ÿ› Report bugs using /bug command

Pinned message:

Welcome to #bugs! ๐Ÿ”ง

Found a problem? Let us know!

**How to report:**
1. Type `/bug` anywhere in this channel
2. Describe the issue in the form
3. Your report will be posted here and tracked on GitHub

**Track your reports:** Use `/mystatus` command

GitHub Integration โ€‹

GitHub Issue Format โ€‹

Issues created with:

  • Labels: enhancement (for features) or bug, discord-submission
  • Milestone: Automatically added to "Prototype" milestone (configurable)
  • GitHub Project: Automatically added to "Lantern App" project (configurable)
  • Priority: Set in GitHub Projects V2 as P0 (critical), P1 (high), P2 (medium), or P3 (low)
  • Body: Discord username, type, priority, impact, description, Firestore ID

GitHub Projects V2 Integration โ€‹

The bot integrates with GitHub Projects V2 to:

  1. Add issues to project - Each new issue automatically added to configured project
  2. Set priority field - Maps Discord priority to GitHub project priority (P0-P3)
  3. Attach milestone - Adds issues to "Prototype" milestone by default

Requirements:

  • GitHub Project V2 must exist with name matching GITHUB_PROJECT_NAME (default: "Lantern App")
  • Project must have "Priority" single-select field with options: P0, P1, P2, P3
  • Milestone named GITHUB_MILESTONE_NAME (default: "Prototype") must exist in repository

Configuration:

bash
# Optional: Change project name (defaults to "Lantern App")
GITHUB_PROJECT_NAME=My Project

# Optional: Change milestone name (defaults to "Prototype")  
GITHUB_MILESTONE_NAME=MVP

GitHub Access for Users โ€‹

Current Setup: Private Repository with Team Access

The repository is private, so users need to be added to the GitHub organization with "Read" access.

What users CAN do (with Read access):

  • โœ… View all issues
  • โœ… Browse code (read-only)
  • โœ… See issue status and comments
  • โœ… Comment on issues

What users CANNOT do:

  • โŒ Push code changes (requires Write permissions)
  • โŒ Merge pull requests
  • โŒ Modify repository settings

Setting Up Team Access:

  1. Add employees to your GitHub organization
  2. Grant "Read" access to the repository
  3. Non-technical staff can safely view but cannot modify code

Troubleshooting โ€‹

Bot doesn't respond to commands โ€‹

Check:

  • Bot is online (npm start running or Railway shows "running")
  • Slash commands are registered (npm run register)
  • Bot has permission to view and send messages in channels
  • DISCORD_GUILD_ID matches your server
  • Bot is in the server and has proper role permissions

Fix:

bash
# Re-register commands
npm run register

# Restart bot
npm start  # local
# or Railway: redeploy

"Invalid interaction application command" error โ€‹

  1. Re-run npm run register
  2. Wait a few minutes for Discord to propagate changes
  3. Restart bot

Slash commands don't appear in Discord โ€‹

  1. Verify bot has applications.commands scope (see OAuth2 setup)
  2. Run npm run register again
  3. Wait up to 1 hour for global propagation
  4. Check bot has permission in channels

"Missing Access" error โ€‹

  1. Verify bot has permissions in channels
  2. Check channel IDs in .env are correct
  3. Ensure bot role is above channel permission overrides

GitHub issue creation fails โ€‹

  1. Verify GITHUB_TOKEN is valid:
    • Go to GitHub โ†’ Settings โ†’ Developer settings โ†’ Tokens
    • Ensure token has repo scope for private repositories
    • Check token hasn't expired
  2. Check GITHUB_REPO format: owner/repo (e.g., cattreedev/lantern_app)
  3. Verify rate limits: https://api.github.com/rate_limit

Firebase errors โ€‹

  1. Verify service account JSON path is correct
  2. Check service account has Firestore permissions
  3. Ensure FIREBASE_PROJECT_ID matches your project
  4. If using file path, check file exists at path

Auto-prompts don't work โ€‹

  1. Enable "Message Content Intent" in Discord Developer Portal
  2. Bot needs permission to "Manage Messages" in channels
  3. Verify auto-prompt code is not disabled in bot.js

Bot goes offline โ€‹

  1. Check Railway dashboard for errors
  2. Verify all environment variables are set correctly
  3. Check GitHub Actions workflows for deployment status
  4. Monitor PM2 logs: pm2 logs lantern-bot

Monitoring & Maintenance โ€‹

Checking Bot Status โ€‹

Local:

  • Check terminal output where npm start is running

Railway:

  • Dashboard โ†’ Logs tab shows real-time logs
  • Deployments tab shows deployment history

PM2 (Self-hosted):

bash
pm2 status
pm2 logs lantern-bot
pm2 restart lantern-bot

Regular Maintenance โ€‹

Monthly:

  • Verify Discord bot token is still valid
  • Check GitHub token hasn't expired
  • Review Firebase quotas and costs

On Channel Changes:

  • Update channel IDs in environment variables
  • Restart bot or redeploy

Updating the Bot:

Local:

bash
git pull
npm install
npm run register
npm start

Railway:

bash
git push  # Auto-deploys

PM2:

bash
cd discord-bot
git pull
npm install
npm run register
pm2 restart lantern-bot

Backup & Recovery โ€‹

Firestore automatically stores all submissions. No additional backup needed for Discord bot. However:

  • Keep .env file safe (in .gitignore, never committed)
  • Store Firebase service account JSON in secure location
  • Keep GitHub token in secure location

Analytics & Monitoring โ€‹

Track submissions via Firestore:

  • Collection: discord_submissions
  • Document: One per submission with timestamp, user, type, status
  • Query: Filter by date, type, priority, status

Security Checklist โ€‹

  • โœ… .env file is in .gitignore (never committed)
  • โœ… Discord bot token kept secure
  • โœ… GitHub token has minimal scope (repo only)
  • โœ… Firebase service account JSON protected
  • โœ… Admin channel is private (only team members can view)
  • โœ… Rate limiting enabled (prevents spam)
  • โœ… Input validation on all fields
  • โœ… User submissions tracked by Discord ID

FAQ โ€‹

Q: Do I need to deploy to both dev and prod?
A: Yes, if you want separate environments. Use different .env files pointing to lantern-app-dev and lantern-app-prod Firebase projects.

Q: Can I use one bot for both environments?
A: No. Create separate bot applications for dev and prod to avoid mixing data.

Q: How much does Railway cost?
A: Free tier gives 500 hours/month. After that, ~$5/month for 24/7 uptime.

Q: What happens if the bot goes offline?
A: Users cannot use slash commands temporarily. When bot comes back online, commands resume. Firestore still stores any submissions made through web forms.

Q: How do I update slash commands?
A: Edit register-commands.js, then run npm run register again.

Q: Can I add more commands?
A: Yes, add to register-commands.js and bot.js, then run npm run register.

Q: What if I have more than 3 channels?
A: The bot currently supports 3 channels (features, bugs, admin-monitor). To add more, modify bot.js and add corresponding environment variables.



Files โ€‹

discord-bot/
โ”œโ”€โ”€ bot.js                    # Main bot implementation
โ”œโ”€โ”€ register-commands.js      # Slash command registration
โ”œโ”€โ”€ package.json             # Dependencies
โ”œโ”€โ”€ .env.example             # Environment template
โ”œโ”€โ”€ .env.testing             # Test environment template
โ”œโ”€โ”€ .gitignore              # Git ignore patterns
โ””โ”€โ”€ README.md               # Quick reference

Summary Checklist โ€‹

After deploying, you should have:

  • โœ… Bot online in Discord (green dot)
  • โœ… Slash commands /feature, /bug, /mystatus available
  • โœ… Auto-prompts working for regular messages
  • โœ… GitHub issues created with correct labels
  • โœ… Priorities mapped to P0-P3 for GitHub Projects
  • โœ… Submissions posted to #features and #bugs channels
  • โœ… Admin notifications in #admin-monitor channel
  • โœ… Firestore storing all submissions
  • โœ… End-to-end tested

Total setup time: ~40 minutes

For additional help, contact the development team.

Built with VitePress