> For the complete documentation index, see [llms.txt](https://docs.luasec.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.luasec.org/protecting-your-script/webhook-protection.md).

# Webhook protection: SEC\_SENDWEBHOOK()

Logging executions to a Discord webhook is common but if the webhook URL ships inside your script (unprotected), anyone who dumps it can **steal or spam** it by hooking the request function. **`SEC_SENDWEBHOOK()`** fixes both.

## Usage

```lua
local function sendExecutionLog()
    SEC_SENDWEBHOOK(
        "https://discord.com/api/webhooks/1234567890/your-webhook-token",
        {
            username = "My Logger",
            embeds = {
                {
                    title = "User executed!",
                    description = "**Discord:** <@%DISCORD_ID%>\n**Key:** ||`%USER_KEY%`||\n**Note:** `%USER_NOTE%`",
                    color = 0xFFFFFF,
                    fields = {
                        {
                            name = "Location",
                            value = "%CLIENT_IP% :flag_%COUNTRY_CODE%:",
                            inline = true
                        }
                    }
                }
            }
        }
    )
end

sendExecutionLog()
```

The first argument **must be a webhook URL string literal** (so it can be extracted at build). The second is a normal Discord webhook payload table.

{% hint style="warning" %}
A non-literal first argument is a build error:

```
SEC_SENDWEBHOOK() takes a webhook URL string literal as its first argument
```

Pass the URL directly as a string, not through a variable.
{% endhint %}

## Server-side placeholders

Put these tokens anywhere in a string in your payload. The **server** replaces them with authoritative values the client can't fake:

| Placeholder      | Filled with                                                             |
| ---------------- | ----------------------------------------------------------------------- |
| `%CLIENT_IP%`    | The executor's IP address (as seen by the API).                         |
| `%COUNTRY_CODE%` | The 2-letter country code (lowercase pairs with Discord's `:flag_xx:`). |
| `%USER_KEY%`     | The license key used.                                                   |
| `%DISCORD_ID%`   | The Discord ID linked to the key (`""` if none).                        |
| `%USER_NOTE%`    | The seller's note on the key.                                           |

<figure><img src="/files/t4JA74b6JUQiM8YpFcJA" alt=""><figcaption></figcaption></figure>

## Notes & limits

* **Privacy:** `%CLIENT_IP%` is sent to **your** Discord webhook, but the platform never stores the raw IP, only the country is kept for analytics.
* **Rebuild required:** the extraction happens at build time, so add `SEC_SENDWEBHOOK` and **rebuild** to enable it.
* **Sanitizing user input:** if you embed player controlled strings (for example usernames), remember they're end-user data. The relay JSON encodes everything (so structural injection isn't possible), but you should still keep player text out of anything that could be abused as discord markdown/mentions.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.luasec.org/protecting-your-script/webhook-protection.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
