Skip to content

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.

ParameterTypeDescription
datatableFull Discord webhook payload (username, avatar_url, embeds, etc.)

tw.webhook.buildEmbed(options)

Builds a Discord embed table.

ParameterTypeDescription
optionstableEmbed options (see below)

Options:

FieldTypeDefaultDescription
titlestringEmbed title
descriptionstring?Embed description
colorinteger?3066993 (green)Embed color (decimal)
fieldstable?{}Array of { name, value, inline }
script_namestring?Added to the footer with a timestamp

Returns: table — Discord embed object.


tw.webhook.getPlayerInfo(source)

Retrieves player information for webhook fields.

ParameterTypeDescription
sourceintegerPlayer server ID

Returns: table

FieldTypeDescription
namestringRP character name
serverIdintegerServer ID
steamstringSteam identifier
charIdstringCharacter identifier

tw.webhook.buildPayload(source, options)

Builds a complete Discord webhook payload with player information automatically included.

ParameterTypeDescription
sourceintegerPlayer server ID
optionstablePayload options (see below)

Options:

FieldTypeDefaultDescription
titlestringEmbed title
descriptionstring?Embed description
colorinteger?3066993Embed color
extra_fieldstable?{}Additional fields appended after the player fields
script_namestring?Footer label
avatar_urlstring?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), orange 16766720 (money), red 15158332 (error).
  • buildPayload automatically adds Player, Server ID, and Steam fields — you do not need to include them in extra_fields.
  • The footer includes the script name and a timestamp when script_name is provided.

Premium RedM Scripts — Multi-Framework