F5 StudioF5 Studio
Skip to main content

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.

config/config_webhooks.lua
Webhooks = {}

Webhooks.defaultUrl = ''

Webhooks.username = 'f5_redeemcode logger'
Webhooks.avatarUrl = ''
Server-only

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:

config/config.lua
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

OptionTypeDefaultDescription
defaultUrlstring''Fallback webhook URL used by any event without its own url. Empty = no default target
usernamestring'f5_redeemcode logger'Username shown on the Discord message
avatarUrlstring''Avatar image shown on the Discord message

Events

config/config_webhooks.lua
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 = '' },
}
EventFires whenDefault color
code_createAn admin creates a code🟢 green (0x2ecc71)
code_update_adminAn admin edits a code🟡 yellow (0xf1c40f)
code_deleteAn admin deletes a code🔴 red (0xe74c3c)
code_redeemA player redeems a code🔵 blue (0x3498db)
history_clearAn admin clears the redemption history🟣 purple (0x9b59b6)

Each event has:

FieldDescription
enabledfalse silences this event only
colorEmbed side color (hex integer)
urlPer-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

config/config_webhooks.lua
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.

The queue block is reserved

config_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

  1. Create a webhook in your Discord channel (Channel Settings → Integrations → Webhooks).
  2. Paste the URL into Webhooks.defaultUrl:
    config/config_webhooks.lua
    Webhooks.defaultUrl = 'https://discord.com/api/webhooks/XXXX/YYYY'
  3. Make sure F5Cfg.Admin.auditWebhook = true.
  4. (Optional) Give any event its own url to route it to a different channel.
  5. Restart the resource.

See Also