Your first bot, from zero to “Pong!”
You’ll create an app, start a small Node.js worker, approve it from your ONYX account, and install it into a text channel. You host the worker. ONYX handles the channel permissions and command events.
- An ONYX account and a server you can manage.
- Node.js 22 or newer on your computer or hosting server.
- The example bot, saved as
onyx-bot.mjs. No packages to install.
01. Give your bot an identity.
Open Settings → Developer in ONYX. Enter a name and choose Create bot. Add a description and profile image, then copy its bot ID or start command.
You can own up to ten bot apps. The bot ID is public; it identifies your app and is not a login token.
02. Start the example worker.
Download the example into a folder on your computer. Open a terminal in that folder and run:
node onyx-bot.mjs YOUR_BOT_IDReplace YOUR_BOT_ID with the ID from Developer settings. The worker asks ONYX for a short-lived connection code. Keep the terminal running while you complete the next step.
03. Connect it to your account.
The terminal prints a verification URL and a ten-character code. Open the URL yourself, sign in to ONYX, and enter that code under Settings → Developer → Approve bot connection.
Approve only a code shown by your own running worker. A connection request expires after five minutes. Once approved, the bot receives its access token directly; the browser never receives or displays it.
04. Choose where it belongs.
In Developer settings, choose your bot under Install bot, select a server, and select the text channels it may use. Save the installation. You must be allowed to manage that server.
For someone else’s server, share the bot’s installation link from Developer settings. That server’s manager makes the decision and chooses the channels. Owning a bot never gives you access to someone else’s server.
05. Say hello with /ping.
The example registers a ping command when it connects. In an approved text channel, type /ping or choose it from the Bot commands menu. Your running worker replies with Pong!
If multiple bots offer the same command, use the menu to pick the right bot. To change the example’s answer, edit the response inside its event loop and restart the worker.
const response = event.command === 'ping'
? 'Pong! Glad you’re here.'
: 'That command is not available.';The full example includes safe event handling and duplicate prevention. Keep that behavior when you customize it.
A small API. Useful building blocks.
The API is version 1. Requests and responses use JSON. Authenticated calls use a bot token in the Authorization: Bearer header. Only the pairing endpoints are unauthenticated.
https://kqalpkxhrsuzdbtyeorb.supabase.co/functions/v1/bot-api| Endpoint | What it does |
|---|---|
POST /pair/start | Start owner-approved pairing. Keep the random device code inside your worker. |
POST /pair/poll | Poll for approval every 3 seconds. The approved token is returned once. |
GET /me | Read this bot’s identity and channel grants. |
POST /commands | Replace the bot’s command list, up to 20 unique commands. |
GET /events?after=CURSOR | Receive up to 50 invoked commands after a string-valued event cursor. |
POST /messages | Send a text reply to an approved channel with a stable UUID nonce. |
{
"commands": [
{
"name": "ping",
"description": "Check whether the bot can answer."
}
]
}{
"channel_id": "CHANNEL_UUID",
"nonce": "A_STABLE_UUID_FOR_THIS_EVENT",
"content": "Pong!"
}Event IDs are strings, not JavaScript numbers. Preserve the same nonce when retrying a reply to avoid duplicates. Advance your event cursor after successfully handling the event. Command events are kept for up to seven days.
Useful access. Clear boundaries.
| Limit | Value |
|---|---|
| Apps per owner | 10 |
| Commands per bot | 20 |
| Authenticated requests | 120 per minute per bot |
| Messages | 30 per minute per bot; channel slowmode also applies |
| Message length | 1–4,000 characters |
| Command invocations | 30 per minute per user |
| Pairing | Once per bot per 30 seconds; code valid for 5 minutes |
| Access token | Up to 30 days; revocable at any time |
A 429 response includes Retry-After: 60. Pause before trying again. Removing an installation or revoking the bot’s access removes its permission to act. Messages cannot use @everyone or @here mentions.
Keep the good stuff running.
Run your worker on your own computer for development. For continuous operation, deploy it to a host that supports a long-running Node.js process. Keep secrets in that host’s protected environment or secret store, and never ship them in a website or repository.
- Handle expiry: stop and reconnect after an authentication failure; do not endlessly retry a revoked token.
- Keep the cursor: save it on your server if your worker needs to resume across restarts.
- Retry safely: reuse nonces and respect rate limits. The example polls every three seconds.
- Log carefully: do not log credentials or unnecessary personal information.
- Ask for less: install only in channels the bot actually needs.
ONYX does not run arbitrary bot code for you. Review third-party workers before connecting them to your account.
When something doesn’t answer.
| What you see | What to check |
|---|---|
| The connection code expired | Restart the worker and approve its new code within five minutes. |
| 401 / access stopped working | The token may have expired or been revoked. Reconnect your worker. |
| 403 / cannot send a reply | Check the installation and selected channels. Also check account or server restrictions. |
| 429 / rate limited | Wait for Retry-After and reduce your request or message frequency. |
| /ping shows no response | Keep the worker running, confirm installation, and select the right bot in the command menu. |
| Duplicate messages after retries | Reuse the same UUID nonce for the same event; advance your cursor after success. |
Still stuck? Send a private report through Settings → Bugs. Include the endpoint, status code and a minimal reproduction, with credentials removed.