LibertyTools / Docs
Send staff requests to Discord
Turn ;staff into a Discord alert using Poll. No server key or SDK needed.
What it does
A player runs ;staff in ERLC and your Discord channel receives a staff request. No Discord bot account, public web address, or ERLC server key is needed.
What you need
- Node.js 22 or newer. Check
node --version. - An ERLC private server with webhook/API access and a LibertyTools connection. Save the connection's webhook URL in ERLC's Event Webhook setting.
- A separate Poll client under Outputs → Poll clients. Select CustomCommand events and include
staff. - A Discord channel webhook from channel settings → Integrations → Webhooks. You need permission to manage webhooks.
Keep the Discord webhook URL and Poll token private. Never paste them into AI chat or Git.
Setup
- Download the project ZIP and extract the entire ZIP. Keep
poll-client.mjsbeside thestaff-helpfolder. - Open a terminal in the extracted
staff-helpfolder. - Copy
.env.exampleto.envand replace the placeholders using a text editor. Do not paste its contents into PowerShell. Check it is not.env.txt. - Run:
npm startNo package installation is needed. Keep the terminal open; Ctrl+C stops the bot.
Test it
Join your ERLC server and run ;staff. Expect a Discord message identifying the requesting player's Roblox ID. This example does not send an in-game reply.
Limits and behavior
- One alert per player per minute, with a shared five-second gap between alerts. Requests inside these cooldowns are intentionally skipped and acknowledged.
- Synthetic test events and unrelated events are ignored. Discord mentions are disabled; player-supplied arguments are not copied to Discord.
- Failed deliveries remain pending. The bot waits before another Discord attempt and respects retry headers. Correct a broken webhook rather than leaving invalid credentials running.
- Up to 5,000 completed event IDs are remembered in memory. A restart or uncertain network response can still cause duplicates. Use durable event-ID storage when duplicates matter.
- This Poll client has its own backlog. It does not consume another client's events or stop forwarding to Melonly or another service.
Common problems
- No event: check the ERLC webhook URL in the dashboard Events tab.
- Event but no alert: check Poll filters, credentials, Discord webhook, cooldowns, and terminal warnings.
- Bot stops: check connection restrictions and Poll credentials. Your process must keep running.
See Poll setup, troubleshooting, and retention limits.
View bot.mjs
import { pathToFileURL } from 'node:url';
import { createPollClient, required, shutdownSignal, retryDelay } from '../poll-client.mjs';
export function createStaffHandler({ webhookUrl, fetcher = fetch, now = Date.now }) {
const url = new URL(webhookUrl);
if (url.protocol !== 'https:' || url.hostname !== 'discord.com' || !/^\/api\/webhooks\/\d+\/[A-Za-z0-9_-]+$/.test(url.pathname) || url.username || url.password || url.search || url.hash) {
throw new Error('Use the Discord channel webhook URL from Integrations → Webhooks.');
}
const cooldowns = new Map();
let nextAlertAt = 0;
let blockedUntil = 0;
return async event => {
if (event.synthetic || event.type !== 'CustomCommand' || event.data?.command !== 'staff') return;
const userId = String(event.data.userId || '');
if (!/^[1-9][0-9]{0,19}$/.test(userId)) return;
const time = now();
if (time < blockedUntil) throw new Error('Waiting before retrying Discord.');
for (const [id, expires] of cooldowns) if (expires <= time) cooldowns.delete(id);
if (time < nextAlertAt || time < (cooldowns.get(userId) || 0)) return;
let response;
try { response = await fetcher(url, { method: 'POST', redirect: 'error', signal: AbortSignal.timeout(10000),
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ content: `Staff requested by Roblox user ${userId}.\nEvent: ${String(event.id).slice(0, 100)}`, allowed_mentions: { parse: [] } }) }); }
catch { blockedUntil = now() + 10000; throw new Error('Discord result uncertain.'); }
if (!response.ok) {
const body = await response.json().catch(() => null);
blockedUntil = now() + Math.max(10000, retryDelay(response, { error: { retryAfterSeconds: body?.retry_after } }, 60000));
throw new Error('Discord did not accept the alert.');
}
const deliveredAt = now();
cooldowns.set(userId, deliveredAt + 60000);
if (cooldowns.size > 1000) cooldowns.delete(cooldowns.keys().next().value);
nextAlertAt = deliveredAt + 5000;
};
}
export async function main(env = process.env) {
const handler = createStaffHandler({ webhookUrl: required(env, 'DISCORD_WEBHOOK_URL') });
const client = createPollClient({ subscriptionId: required(env, 'POLL_SUBSCRIPTION_ID'), token: required(env, 'POLL_TOKEN') });
console.log('Listening for ;staff. Keep this terminal open. Ctrl+C stops the bot.');
await client.run(handler, { signal: shutdownSignal() });
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) main().catch(() => {
console.error('Staff bot stopped. Check the Poll credentials, connection status, and Discord webhook.'); process.exitCode = 1;
});