@anura-gate/watcher-discord
v0.2.0
Published
GATE Watcher — Self-hosted daemon for Discord account monitoring. Token never leaves your machine.
Maintainers
Readme
GATE Watcher — Discord
Self-hosted daemon that monitors your Discord account and pushes message events to GATE cloud for security processing. Your Discord token never leaves your machine.
How it works
Your Machine (Watcher) GATE Cloud
┌─────────────────────┐ ┌──────────────────┐
│ Discord account │───────>│ Security pipeline │
│ (token stays HERE) │<───────│ (redact, policy, │
│ │ poll │ audit, forward) │
└─────────────────────┘ └──────────────────┘Quick Start (CLI)
cd gate-watcher-discord
npm install
# Create .env (or pass env vars directly)
cp .env.example .env
# Fill in GATE_KEY, GATE_INTEGRATION_ID, DISCORD_TOKEN
npm startEmbed in Your App (SDK)
npm install @anura-gate/watcher-discordconst { GateDiscordWatcher } = require("@anura-gate/watcher-discord");
const watcher = new GateDiscordWatcher({
gateKey: "gk-xxx",
integrationId: "int_xxx",
discordToken: "your-discord-token",
});
watcher.on("ready", (user) => {
console.log(`Discord connected: ${user.tag}`);
});
// Every incoming message after GATE security processing
watcher.on("message", (message, result) => {
console.log(`From: ${message.author.tag}, Text: ${message.content}`);
console.log(`Security actions: ${result.securityActions}`);
console.log(`Blocked: ${result.blocked}`);
});
// Messages sent by you (from any device)
watcher.on("message_sent", (message, result) => {
console.log(`Sent: ${message.content}`);
});
watcher.on("action_result", ({ action, success, error }) => {
console.log(`${action}: ${success ? "done" : error}`);
});
await watcher.start();
// Later...
await watcher.stop();SDK Events
| Event | Args | Description |
|---|---|---|
| ready | (user) | Connected to Discord |
| message | (message, result) | Incoming message processed by GATE |
| message_sent | (message, result) | Outgoing message processed by GATE |
| message_update | (oldMsg, newMsg, result) | Message edited, processed by GATE |
| message_delete | (message, result) | Message deleted, processed by GATE |
| action | (action) | Outbound action received from GATE queue |
| action_result | ({ actionId, action, success, result, error }) | Outbound action completed |
| gate_error | ({ path, status, error }) | GATE API call failed |
| limit_reached | (type) | Plan limit hit |
| disconnected | (reason) | Disconnected from Discord |
| stopped | — | Watcher fully shut down |
SDK Options
| Option | Required | Default | Description |
|---|---|---|---|
| gateKey | Yes | — | Virtual key (gk-xxx) |
| integrationId | Yes | — | Integration ID (int_xxx) |
| discordToken | Yes | — | Discord user token |
| gateUrl | No | "https://anuragate.com" | GATE cloud URL |
| heartbeatInterval | No | 30000 | ms between heartbeats |
| pollInterval | No | 3000 | ms between outbound polls |
| sessionId | No | — | Session ID for multi-tenant use |
| sessionLabel | No | — | Human-readable session label |
| sessionMetadata | No | {} | Arbitrary metadata for the session |
Advanced: Access discord.js directly
const client = watcher.getDiscordClient();
const guilds = client.guilds.cache;Setup
- Go to GATE Dashboard → Integrations → Add Integration
- Select Discord, copy the Integration ID
- Copy your Virtual Key from the Keys page
- Set the env vars and run
Environment Variables
| Variable | Required | Description |
|---|---|---|
| GATE_KEY | Yes | Your GATE virtual key |
| GATE_INTEGRATION_ID | Yes | Integration ID from the dashboard |
| DISCORD_TOKEN | Yes | Your Discord user token |
| GATE_URL | No | Custom GATE cloud URL |
| WEB_PORT | No | Port for the dev dashboard (CLI only) |
Security model
- Discord token stored in
.envon YOUR machine - GATE cloud never sees or stores your credentials
- All message content passes through GATE's security pipeline
- Both incoming and outgoing messages are reported to GATE
- Billing, limits, and security enforced server-side
