Real-time Discord Gateway bot for processing TMI coordination reactions instantly.
This bot connects to Discord via WebSocket (Gateway) and listens for reaction events on TMI coordination threads. When a facility representative adds a reaction to approve or deny a TMI proposal, the bot immediately calls the PHP API to process the vote.
Benefits over polling:
- Instant reaction processing (vs 15-60 second polling delay)
- No wasted API calls checking for reactions
- Scales to any volume without additional load
- Node.js 18+
- npm
- Discord Bot Token (from main VATUSA Discord server)
The bot must be deployed to the main VATUSA Discord server (not the backup server) to access:
- The
#coordinationchannel where TMI coordination threads are created - Facility-specific emoji for approval reactions (e.g., :ZNY:, :ZDC:)
- DCC Staff and NTMO role verification for override permissions
Contact VATUSA/DCC staff to obtain:
- Bot Token - From Discord Developer Portal (bot must be invited to main server)
- Guild ID - The main VATUSA Discord server ID
- Coordination Channel ID - The
#coordinationchannel ID
The bot runs as part of the Azure App Service deployment. It is started automatically by scripts/startup.sh alongside all other daemons:
# In scripts/startup.sh:
cd /home/site/wwwroot/discord-bot && node bot.js >> /home/LogFiles/discord-bot.log 2>&1 &No separate server is needed.
cd discord-bot
npm install
cp .env.example .env
# Edit .env with backup server credentials for testingEdit .env with your values:
# Discord Bot Token (from Discord Developer Portal)
# Bot must be invited to the main VATUSA Discord server
DISCORD_BOT_TOKEN=your_actual_bot_token_here
# Discord Guild (Server) ID - Main VATUSA Discord server
# Contact DCC staff for the production server ID
DISCORD_GUILD_ID=YOUR_GUILD_ID_HERE
# Coordination Channel ID (parent channel where threads are created)
# This is the #coordination channel in the main VATUSA Discord
COORDINATION_CHANNEL_ID=YOUR_COORDINATION_CHANNEL_ID_HERE
# PHP API Configuration
API_BASE_URL=https://perti.vatcscc.org
API_KEY=
# Logging level: debug, info, warn, error
LOG_LEVEL=info| Environment | Discord Server | Notes |
|---|---|---|
| Development/Testing | Backup Server | Join here |
| Production | Main VATUSA Discord | Requires DCC approval and credentials |
The .env.example file contains backup server IDs for testing. For production deployment, you must obtain the main VATUSA Discord server credentials from DCC staff.
TMI advisories can be posted to multiple Discord servers simultaneously using MultiDiscordAPI.php. Each organization has its own webhook configuration:
// In load/config.php
define('DISCORD_MULTI_ORG_ENABLED', true);
define('DISCORD_ORGANIZATIONS', [
'VATUSA' => ['webhook_url' => '...', 'guild_id' => '...'],
'VATCAN' => ['webhook_url' => '...', 'guild_id' => '...'],
]);The bot's reaction processing calls api/mgt/tmi/coordinate.php via REST. The cleanup-coordination.js utility handles stale coordination threads.
# Run in foreground to test
npm start
# You should see:
# [timestamp] [INFO] Starting PERTI TMI Coordination Bot...
# [timestamp] [INFO] Bot logged in as vATCSCC TMU#7270
# [timestamp] [INFO] Watching coordination channel: 1466013550450577491Test by adding a reaction to a coordination thread message.
# Via Kudu SSH
tail -f /home/LogFiles/discord-bot.log
# Via Azure CLI
az webapp log tail --name vatcscc --resource-group perti-rg- Check token is correct in
.env - Verify bot has correct intents in Discord Developer Portal:
- Server Members Intent (for role checking)
- Message Content Intent (for message access)
- Check logs:
sudo journalctl -u perti-bot -n 50
- Verify bot is in the correct guild
- Check coordination channel ID is correct
- Verify threads are under that channel
- Check API endpoint is reachable:
curl https://perti.vatcscc.org/api/mgt/tmi/coordinate.php?list=pending
- Check API_BASE_URL is correct
- Verify PHP API is accepting PUT requests
- Check coordination_debug.log on the server
Ensure these are enabled for your bot at https://discord.com/developers/applications:
Bot > Privileged Gateway Intents:
- Server Members Intent
- Message Content Intent
OAuth2 > URL Generator > Scopes:
- bot
OAuth2 > URL Generator > Bot Permissions:
- Read Messages/View Channels
- Read Message History
- Add Reactions