@anura-gate/watcher-discord-bot
v0.2.0
Published
GATE Watcher — Self-hosted daemon for Discord Bot integration. Bot token never leaves your machine.
Maintainers
Readme
GATE Watcher — Discord Bot
Self-hosted daemon that connects your Discord Bot to GATE cloud for security processing. Your bot token never leaves your machine.
How it works
Your Machine (Watcher) GATE Cloud
┌─────────────────────┐ ┌──────────────────┐
│ Discord Bot session │───────>│ Security pipeline │
│ (token stays HERE) │<───────│ (redact, policy, │
│ │ poll │ audit, forward) │
└─────────────────────┘ └──────────────────┘Quick Start (CLI)
cd gate-watcher-discord-bot
npm install
# Create .env (or pass env vars directly)
cp .env.example .env
# Fill in GATE_KEY, GATE_INTEGRATION_ID, DISCORD_BOT_TOKEN
npm startEmbed in Your App (SDK)
npm install @anura-gate/watcher-discord-botconst { GateDiscordBotWatcher } = require("@anura-gate/watcher-discord-bot");
const watcher = new GateDiscordBotWatcher({
gateKey: "gk-xxx",
integrationId: "int_xxx",
botToken: "your-bot-token",
});
watcher.on("ready", (username, guildCount) => {
console.log(`Discord Bot connected: ${username} in ${guildCount} servers`);
});
// Every 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}`);
});
watcher.on("member_add", (member) => {
console.log(`New member: ${member.user.tag} joined ${member.guild.name}`);
});
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 | (username, guildCount) | Bot connected to Discord |
| message | (message, result) | Message received and processed by GATE |
| member_add | (member) | Member joined a guild |
| member_remove | (member) | Member left a guild |
| interaction | (interaction) | Slash command or component interaction |
| 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 |
| stopped | — | Watcher fully shut down |
SDK Options
| Option | Required | Default | Description |
|---|---|---|---|
| gateKey | Yes | — | Virtual key (gk-xxx) |
| integrationId | Yes | — | Integration ID (int_xxx) |
| botToken | Yes | — | Discord bot token |
| gateUrl | No | "https://anuragate.com" | GATE cloud URL |
| intents | No | ["Guilds", "GuildMessages", "MessageContent", "GuildMembers", "DirectMessages"] | Gateway intents |
| 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 guild = await client.guilds.fetch("guild-id");Setup
- Go to discord.com/developers/applications and create a new application
- Under Bot, click Add Bot and copy the Bot Token
- Under Bot → Privileged Gateway Intents, enable Message Content Intent and Server Members Intent
- Under OAuth2 → URL Generator, select
botscope and the permissions your bot needs, then invite it to your server - Go to GATE Dashboard → Integrations → Add Integration, select Discord Bot, copy the Integration ID
- Copy your Virtual Key from the Keys page
Environment Variables
| Variable | Required | Description |
|---|---|---|
| GATE_KEY | Yes | Your GATE virtual key |
| GATE_INTEGRATION_ID | Yes | Integration ID from the dashboard |
| DISCORD_BOT_TOKEN | Yes | Discord bot token |
| GATE_URL | No | Custom GATE cloud URL |
| WEB_PORT | No | Port for the dev dashboard (CLI only) |
Security model
- Discord bot token stored in
.envon YOUR machine - GATE cloud never sees or stores your credentials
- All message content passes through GATE's security pipeline
- Billing, limits, and security enforced server-side
