# REQ-2026-04-15-discord-action-log

**From:** Chronicler #92  
**Date:** 2026-04-15  
**Priority:** HIGH — troubleshooting on a live system  
**Status:** PENDING  
**Linked Issue:** Issue #1 — Arbiter Action Logs

## Note from Michael

We need to be able to verify what Arbiter is doing in Discord. On launch day we can't tell if the Wanderer role fired, if the link reminder DM went out, or if reaction roles are assigning correctly without digging through logs manually. This gives us a simple audit trail.

## What Needs to Be Built

### 1. CREATE migration — `discord_action_log` table

```sql
CREATE TABLE discord_action_log (
    id SERIAL PRIMARY KEY,
    action_type VARCHAR(50) NOT NULL,
    discord_id VARCHAR(50),
    username VARCHAR(100),
    details JSONB DEFAULT '{}',
    success BOOLEAN DEFAULT TRUE,
    error_message TEXT,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

CREATE INDEX idx_discord_action_log_discord_id ON discord_action_log(discord_id);
CREATE INDEX idx_discord_action_log_action_type ON discord_action_log(action_type);
CREATE INDEX idx_discord_action_log_created_at ON discord_action_log(created_at DESC);
```

### 2. CREATE src/services/discordActionLog.js

Simple service that writes to the table. Silent-fail — never let logging break the action it's logging.

### 3. MODIFY these files to call logAction:

- src/discord/reactionRoles.js — log every reaction add/remove (role assigned/removed, emoji, message)
- src/discord/events.js guildMemberAdd — log Wanderer role assignment + welcome DM
- src/routes/stripe.js — log link reminder DM (success or DMs closed)

### 4. ADD Trinity Console view

New route: GET /admin/discord-log  
Simple table: recent 100 actions, filterable by action_type and discord_id search.  
Action types: reaction_role_add, reaction_role_remove, wanderer_assigned, welcome_dm, link_reminder_dm

## Files to Touch
- New: migrations/142_discord_action_log.sql
- New: src/services/discordActionLog.js
- New: src/routes/admin/discord-log.js
- New: src/views/admin/discord-log.ejs
- Modify: src/discord/reactionRoles.js
- Modify: src/discord/events.js
- Modify: src/routes/stripe.js
- Modify: src/routes/admin/about.js (add to nav)
- Modify: src/views/layout.ejs (sidebar link)
