Discord Gateway / WebSocket Note
TL;DR
WordPress (PHP) can poll Discord via REST, but it cannot reliably maintain a Gateway WebSocket connection inside the normal WP request lifecycle. That means:
- ✅ Bot works via REST polling
- ✅ Tools/agent logic stays fully inside WordPress
- ❌ Bot won’t appear online (presence requires Gateway WS)
- ❌ True realtime events require an always-on WS client
Why WebSockets aren’t WordPress-native
- WP requests are short-lived; WebSocket clients are long-running
- Many hosts kill long-running PHP processes
- Shared hosting often blocks sockets
- WP has no built-in daemon/process supervisor
Current Approach (WP-only)
- Action Scheduler polling every 60s (with async runs triggered on inbound webhooks when possible)
- REST API for inbound/outbound
- Works today, no extra services
Optional Companion (for parity)
A tiny gateway companion (Node/Go or Sweatpants module) can:
- Maintain Discord Gateway WS
- Forward events to wp-agent REST
- Provide online presence + realtime response
This companion is optional — the WP-only path remains fully functional.
Status
We are not blocked by WebSocket limitations. It’s a parity enhancement, not a blocker.