tw.webhook
Side: Server
Discord webhook logging system. Reads Config.Webhook automatically to determine the dispatch method.
Config
Each script using webhooks must define this in its settings:
lua
-- config/_default.lock/settings.lua
Config.Webhook = {
type = 'discord', -- 'discord' or 'custom'
url = '', -- Discord webhook URL (only used with 'discord' type)
}When type is 'custom', the module calls the global SendScriptWebhook(data) function instead of posting to Discord. See the custom webhooks guide for details.
Functions
tw.webhook.dispatch(data)
Sends the payload to Discord or to the custom handler based on Config.Webhook.type.
| Parameter | Type | Description |
|---|---|---|
data | table | Full Discord webhook payload (username, avatar_url, embeds, etc.) |
tw.webhook.buildEmbed(options)
Builds a Discord embed table.
| Parameter | Type | Description |
|---|---|---|
options | table | Embed options (see below) |
Options:
| Field | Type | Default | Description |
|---|---|---|---|
title | string | — | Embed title |
description | string? | — | Embed description |
color | integer? | 3066993 (green) | Embed color (decimal) |
fields | table? | {} | Array of { name, value, inline } |
script_name | string? | — | Added to the footer with a timestamp |
Returns: table — Discord embed object.
tw.webhook.getPlayerInfo(source)
Retrieves player information for webhook fields.
| Parameter | Type | Description |
|---|---|---|
source | integer | Player server ID |
Returns: table
| Field | Type | Description |
|---|---|---|
name | string | RP character name |
serverId | integer | Server ID |
steam | string | Steam identifier |
charId | string | Character identifier |
tw.webhook.buildPayload(source, options)
Builds a complete Discord webhook payload with player information automatically included.
| Parameter | Type | Description |
|---|---|---|
source | integer | Player server ID |
options | table | Payload options (see below) |
Options:
| Field | Type | Default | Description |
|---|---|---|---|
title | string | — | Embed title |
description | string? | — | Embed description |
color | integer? | 3066993 | Embed color |
extra_fields | table? | {} | Additional fields appended after the player fields |
script_name | string? | — | Footer label |
avatar_url | string? | — | Webhook avatar URL |
Returns: table — Full Discord webhook payload with Player, Server ID, and Steam fields auto-included.
Examples
Full payload with extra fields
lua
local payload = tw.webhook.buildPayload(source, {
title = "Item Collected",
description = "A player collected an item",
color = 3066993,
script_name = "twinded_collect",
avatar_url = "https://example.com/avatar.png",
extra_fields = {
{ name = "Item", value = "Apple x5", inline = true },
{ name = "Zone", value = "Valentine", inline = true },
},
})
tw.webhook.dispatch(payload)Simple embed dispatch
lua
local embed = tw.webhook.buildEmbed({
title = "Server Event",
description = "Something happened",
color = 15158332, -- red
script_name = "twinded_collect",
})
tw.webhook.dispatch({ embeds = { embed } })Notes
- Common colors: green
3066993(success), orange16766720(money), red15158332(error). buildPayloadautomatically adds Player, Server ID, and Steam fields — you do not need to include them inextra_fields.- The footer includes the script name and a timestamp when
script_nameis provided.

