Discord Webhooks
F5 Redeem Code can mirror every meaningful action to Discord as rich embeds — code creation, edits, deletions, player redemptions and history clears. Configuration lives in a server-only file.
Webhooks = {}
Webhooks.defaultUrl = ''
Webhooks.username = 'f5_redeemcode logger'
Webhooks.avatarUrl = ''
config/config_webhooks.lua is loaded only on the server (it's in the manifest's server_scripts). Never move webhook URLs into config.lua — they must not reach clients.
Master switch
Webhooks are additionally gated by the admin config:
F5Cfg.Admin = { auditWebhook = true }
If auditWebhook = false, no webhooks are sent regardless of anything below. This is the single on/off switch for all Discord logging.
Global settings
| Option | Type | Default | Description |
|---|---|---|---|
defaultUrl | string | '' | Fallback webhook URL used by any event without its own url. Empty = no default target |
username | string | 'f5_redeemcode logger' | Username shown on the Discord message |
avatarUrl | string | '' | Avatar image shown on the Discord message |
Events
Webhooks.events = {
code_create = { enabled = true, color = 0x2ecc71, url = '' },
code_delete = { enabled = true, color = 0xe74c3c, url = '' },
code_redeem = { enabled = true, color = 0x3498db, url = '' },
history_clear = { enabled = true, color = 0x9b59b6, url = '' },
code_update_admin = { enabled = true, color = 0xf1c40f, url = '' },
}
| Event | Fires when | Default color |
|---|---|---|
code_create | An admin creates a code | 🟢 green (0x2ecc71) |
code_update_admin | An admin edits a code | 🟡 yellow (0xf1c40f) |
code_delete | An admin deletes a code | 🔴 red (0xe74c3c) |
code_redeem | A player redeems a code | 🔵 blue (0x3498db) |
history_clear | An admin clears the redemption history | 🟣 purple (0x9b59b6) |
Each event has:
| Field | Description |
|---|---|
enabled | false silences this event only |
color | Embed side color (hex integer) |
url | Per-event webhook URL. Empty → falls back to Webhooks.defaultUrl |
This lets you route, say, code_redeem to a public channel and admin actions to a staff channel.
URL validation
Webhooks.urlValidationPattern = '^https://[%w%.%-]*discord[%w]*%.com/api/webhooks/'
Before every send, the resolved URL is matched against this Lua pattern. A URL that doesn't look like a Discord webhook endpoint is rejected and logged under the WEBHOOK debug category — a safety net against pasting the wrong value. Adjust it only if you use a Discord-compatible proxy.
How dispatch works
When an event fires, the server builds an embed (title, description, fields, and a YYYY-MM-DD HH:MM:SS footer timestamp) and sends it with PerformHttpRequest. A non-200/204 response is logged as a warning under the WEBHOOK category. Dispatch is fire-and-forget and never blocks gameplay.
An event is only sent when all of these hold: auditWebhook = true, the event's enabled = true, a non-empty URL resolves (event url or defaultUrl), and that URL passes urlValidationPattern.
queue block is reservedconfig_webhooks.lua contains a Webhooks.queue table (tickMs, maxSize, retryAfterMaxSec, requestTimeoutMs, retry5xxOnce). These are not currently used — the current build dispatches directly without a retry queue. They are safe to leave as-is.
Quick setup
- Create a webhook in your Discord channel (Channel Settings → Integrations → Webhooks).
- Paste the URL into
Webhooks.defaultUrl:config/config_webhooks.luaWebhooks.defaultUrl = 'https://discord.com/api/webhooks/XXXX/YYYY' - Make sure
F5Cfg.Admin.auditWebhook = true. - (Optional) Give any event its own
urlto route it to a different channel. - Restart the resource.
See Also
- Configuration → Admin Panel — the
auditWebhookmaster switch - Admin Panel — the actions that trigger webhooks
- Features — the redemption flow behind
code_redeem