# Discord Logs Setup

NoLag Properties can send property-related events to Discord channels via webhooks. This guide walks you through enabling Discord logs and configuring webhooks.

### Requirements

* A Discord server where you can create webhooks
* Permission to create webhooks in the target channel(s)

### Step 1: Enable Discord logs in config

In `config.lua`, set the log method to `"discord"`:

```lua
--[[
    Supported log methods:
    * ox_lib
    * discord
    ! You can add your own in custom/logs/
]]
Logs = "discord",
```

### Step 2: Create Discord webhooks

1. In Discord, open the channel where you want logs (e.g. **#property-logs**).
2. Go to **Channel settings** → **Integrations** → **Webhooks** → **New Webhook**.
3. Name the webhook (e.g. "NoLag Properties") and copy the **Webhook URL**.
4. Repeat for other channels if you want to split logs by category (see below).

**Security:** Never share webhook URLs or commit them to your repo. Use ConVars in `server.cfg` so they stay server-side.

### Step 3: Configure webhooks in server.cfg

Webhooks are set via **ConVars**. Add these to your `server.cfg` **before** the `ensure nolag_properties` line (replace the URLs with your real webhook URLs):

```cfg
# General fallback – used when a specific webhook is not set
setr propertiesDiscordWebhook "https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN"

# Optional: separate webhooks per category (omit to use the general webhook)
setr propertiesPropertyWebhook "https://discord.com/api/webhooks/..."
setr propertiesBuildingWebhook "https://discord.com/api/webhooks/..."
setr propertiesKeyholderWebhook "https://discord.com/api/webhooks/..."
setr propertiesDoorWebhook "https://discord.com/api/webhooks/..."
setr propertiesRaidWebhook "https://discord.com/api/webhooks/..."
setr propertiesTransactionWebhook "https://discord.com/api/webhooks/..."
```

* **Order matters:** declare these ConVars **before** `ensure nolag_properties` in `server.cfg`, or the resource will not see them.
* You **must** set at least `propertiesDiscordWebhook` (or every specific webhook). If a specific one is missing, the general webhook is used.
* If you want all logs in one channel, set only `propertiesDiscordWebhook`.

### Webhook types and events

| Webhook type    | ConVar                         | Events                                                                                |
| --------------- | ------------------------------ | ------------------------------------------------------------------------------------- |
| **property**    | `propertiesPropertyWebhook`    | Property created, deleted, set for sale                                               |
| **building**    | `propertiesBuildingWebhook`    | Building created, deleted                                                             |
| **keyholder**   | `propertiesKeyholderWebhook`   | Key holder added/removed, all key holders removed, lock re-keyed, physical key issued |
| **door**        | `propertiesDoorWebhook`        | Door added, door removed                                                              |
| **raid**        | `propertiesRaidWebhook`        | Property raided (lockpick success)                                                    |
| **transaction** | `propertiesTransactionWebhook` | Property bought, rented, rent extended, rent cancelled, property sold                 |

### Example: one channel for everything

```cfg
setr propertiesDiscordWebhook "https://discord.com/api/webhooks/123456789/abcdef..."
```

All events will go to the channel that owns this webhook.

### Example: separate channels for transactions and raids

```cfg
setr propertiesDiscordWebhook "https://discord.com/api/webhooks/111/aaa..."
setr propertiesTransactionWebhook "https://discord.com/api/webhooks/222/bbb..."
setr propertiesRaidWebhook "https://discord.com/api/webhooks/333/ccc..."
```

* Transactions (buy, rent, sell, etc.) → transaction webhook channel.
* Raids → raid webhook channel.
* Everything else (property/building/keyholder/door) → general webhook channel.

### What gets logged

The Discord log module sends embeds for:

* **Property** – Create, delete, set for sale
* **Building** – Create, delete
* **Transactions** – Buy, rent, extend rent, cancel rent, sell
* **Keyholders** – Add, remove, remove all
* **Doors** – Add, remove
* **Raid** – Property raided
* **Locks** – Re-key lock, issue physical key

Each embed includes relevant IDs, player identifiers, labels, and prices where applicable.

### Troubleshooting

* **No logs in Discord**
  * Ensure `Logs = "discord"` in `config.lua`.
  * Restart the resource after changing config or ConVars.
  * Check that the webhook URL in `server.cfg` is correct and the webhook wasn’t deleted in Discord.
* **Wrong channel**\
  Each webhook is tied to the channel where it was created. Use the correct webhook URL for the channel you want.
* **"SET\_YOUR\_WEBHOOK\_IN\_SERVER.CFG" in logs**\
  The default placeholder is being used because no ConVar was set. Add `setr propertiesDiscordWebhook "..."` (and any specific webhooks) to `server.cfg`.

### Customizing the Discord log content

The Discord log logic lives in `custom/logs/discord.lua`. You can edit that file to change embed titles, colors, fields, or add new ones. Restart the resource after editing.
