Send Discord notifications from your app
A Discord webhook is a single secret URL that posts into one channel. It is the fastest way to bring your community into what your app is doing.

Key takeaways
- A Discord webhook URL is a password: anyone who has it can post to your channel. Keep it in Backend → Secrets and post from an edge function.
- Always send allowed_mentions with an empty parse list when a message includes user-written text, or a player name can ping your whole server.
- Batch noisy events into digests and back off on HTTP 429 using the retry time Discord returns.
To send Discord notifications from your app, create a webhook in the channel's settings (Edit Channel, Integrations, Webhooks), copy its URL into your backend secrets, and have a server function POST a JSON message to that URL whenever something worth announcing happens. No bot, no OAuth and no Discord app review are needed for one-way posts. The work is in keeping the URL secret, formatting messages people want to read, and not flooding the channel.
What you'll build
The example is a browser game with a Discord community. Three events post to two channels: a new all-time high score goes to `#hall-of-fame` as a rich card with the player name, score and a link to play; a new level published by a player goes there too; and a server error spike goes to a private `#ops` channel for you. Each channel gets its own webhook, so a leak of one cannot post to the other.
What you need
- Manage Webhooks permission on the Discord server (you have it if you own the server).
- One webhook per channel. Name it after your game and give it an avatar; posts will show that name and picture.
- The URLs in [Backend → Secrets](https://docs.startbase.ai/cloud/cloud-secrets), for example `DISCORD_WEBHOOK_HALL_OF_FAME` and `DISCORD_WEBHOOK_OPS`.
- A backend with edge functions to do the posting.
Why not post from the game itself? Because the browser would need the webhook URL, and then any player could open developer tools, copy it and post whatever they like as your game, including spam or worse, until you notice and delete the webhook.
The data flow
- 01A run ends. The game submits the score to your `submit-score` function, which validates it (plausible for the run length, signed-in player, not flagged) and saves it.
- 02If the score beats the current record, the function inserts a row into `discord_outbox`: `channel: "hall_of_fame"`, `payload` (the message JSON), `status: "pending"`.
- 03A `post-discord` function sends pending outbox rows to the right webhook URL and marks them `sent` with the returned message id, or `failed` with the error.
- 04On HTTP 429 it stops, reads `retry_after` from the response, and leaves the remaining rows for the next run.
The outbox step looks like extra work, but it means a Discord outage never slows down score submission, and a failed post can be retried without the player doing anything. It also gives you one place to apply a daily cap.
Writing messages people read
A webhook message has plain `content` (up to 2,000 characters) and up to 10 `embeds`. An embed is a card with a title, description, URL, color, fields, thumbnail, image and footer. For a high score, one embed reads better than a line of text:
- Title: New record on Lantern Run
- Description: mika_88 scored 48,210, beating the old record by 1,940.
- Fields: Level: Sunken Docks, Time: 3:42, Previous holder: torvald
- URL: a link to the leaderboard, and an image of the level if you have one.
- Color: your brand color as an integer.
Add `?wait=true` to the webhook URL when you want Discord to return the created message. Store its id, and you can later edit the message (for example to add 'record broken 2 hours later') with a PATCH to the same webhook.
Choosing what is worth a post
A community channel works when every post is something members would tell each other about. For a game, good candidates are rare by nature: a new all-time record, a daily challenge winner, a player-made level reaching 100 plays, a new season or update going live. Poor candidates happen constantly: every score, every signup, every login. A useful test is frequency. If an event could fire more than about 20 times a day at your current player count, it belongs in a digest, not its own post.
Digests are easy with the outbox. Mark routine events `digest: true`, and an evening job groups them into one embed: 'Today on Lantern Run: 312 runs, 14 new personal bests, top score 31,880 by ren_k.' Members get the pulse of the game without the noise, and your channel stays far below any rate limit.
Block accidental pings
Player names, level titles and chat messages are user-written. If a player names themselves `@everyone` and your message includes that name, Discord will notify every member of your server. Include `"allowed_mentions": { "parse": [] }` in every payload that contains user text, which turns all mention parsing off. If you do want to ping a role for big moments, list that one role id explicitly in `allowed_mentions.roles`. Also escape Discord markdown in names so `**` and `||` render as characters, not formatting.
Paste-ready brief
Post game events to my Discord server with webhooks. URLs are in Secrets as DISCORD_WEBHOOK_HALL_OF_FAME and DISCORD_WEBHOOK_OPS. When a validated score beats the all-time record, or a player publishes a level, add a row to a discord_outbox table with the channel and an embed payload (title, description, fields for level and time, leaderboard link, brand color). Write an edge function post-discord that sends pending rows, uses ?wait=true and stores the message id, sets allowed_mentions parse to an empty list on every message, escapes Discord markdown in player text, and stops on a 429 until retry_after passes. Run it every minute. Cap hall-of-fame posts at 20 a day and roll extras into one evening digest. Post an ops alert if more than 10 function errors happen in 5 minutes.
Pitfalls
- The URL in client code or a public repo. Treat it like a password. If it leaks, delete the webhook in Discord and create a new one; there is no way to 'rotate' the old one.
- Flooding. Discord rate-limits each webhook and returns 429 with a retry time when you go over. A busy game should post records and milestones, not every score, and roll the rest into a digest.
- Cheated scores going public. Validate on the server before posting. A fake record announced to your community is worse than one quietly sitting in a table.
- Personal data. Post display names, never emails or real names unless players opted in. Add a 'Show me in Discord announcements' setting, on by default only if your terms say so, and respect it in the outbox step.
- Deleted webhooks. If someone removes the webhook in Discord, every post returns 404. Mark the channel disabled after a few 404s and alert yourself, instead of retrying forever.
- Using a webhook for two-way chat. Webhooks only post. Reading messages, slash commands or reacting to members needs a Discord bot, which is a separate project with its own token and gateway connection.
For the score validation side, the leaderboards guide covers server-side checks in depth, and the webhook glossary entry explains the general pattern if you are new to it.
Frequently asked questions
Do I need a Discord bot to send messages from my app?
No. For one-way posts into a channel, a webhook is enough: no bot account, no OAuth. You need a bot only to read messages, respond to commands or act on members.
Is it safe to put a Discord webhook URL in my frontend?
No. Anyone with the URL can post to your channel. Store it in Backend → Secrets and post from an edge function after your own checks.
How do I stop messages from pinging everyone?
Send allowed_mentions with an empty parse list in the payload. That disables @everyone, @here, role and user mentions unless you list specific ids.
What happens if I send too many webhook messages?
Discord returns HTTP 429 with a retry time. Wait that long before the next post, and batch frequent events into digests so you rarely hit the limit.

