# Discord Webhook Logs

Discord Logs — moh-billing

moh-billing sends rich Discord embeds for every significant action. Logging is completely optional — leave `Config.Webhook` empty to disable it.

### Setup

1. In your Discord server, go to a channel's **Settings → Integrations → Webhooks**.
2. Click **New Webhook**, give it a name and optional avatar, then copy the URL.
3. Paste the URL into `config.lua`:

   ```
   Config.Webhook    = 'https://discord.com/api/webhooks/YOUR_ID/YOUR_TOKEN'
   Config.ServerName = 'My RP Server'
   Config.IconURL    = 'https://yourserver.com/logo.png'   -- optional
   ```

### Logged events

| Event                            | Config colour key | Default colour | Trigger                                                         |
| -------------------------------- | ----------------- | -------------- | --------------------------------------------------------------- |
| 📄 Invoice Created               | `invoiceCreated`  | Blue           | A new invoice is sent to a player.                              |
| ✅ Invoice Paid → Management      | `invoicePaid`     | Green          | Invoice paid; money goes to society fund.                       |
| ✅ Invoice Paid → Player          | `invoicePaid`     | Green          | Invoice paid; money goes directly to sender.                    |
| ✅ Invoice Paid → Split           | `invoicePaid`     | Green          | Invoice paid; money split between sender and fund.              |
| ❌ Insufficient Funds             | `invoiceFailed`   | Red            | Player attempted to pay but had insufficient balance.           |
| ⚠️ Invoice Not Found             | `invoiceFailed`   | Red            | Pay event triggered with an invalid or already-paid invoice ID. |
| 💸 Management Withdrawal         | `withdraw`        | Yellow         | Boss withdraws funds from society account.                      |
| 💰 Management Deposit            | `deposit`         | Green          | Boss deposits funds into society account.                       |
| 🚫 Unauthorized Withdraw/Deposit | `invoiceFailed`   | Red            | Player triggered a management event without boss grade.         |

### Embed fields by event type

#### Invoice Created

* **Author** — name and society of the sender
* **Receiver** — name of the target player
* **Item** — reason entered in the UI
* **Amount** — invoice value in $
* **Due in** — days until deadline (if `Config.LimitDate` is true)

#### Invoice Paid

* **Payer** — who paid
* **Invoice #** — database ID
* **Amount / Total** — amount paid
* **Item** — invoice reason
* **Society** — society name
* *split mode only:* **To Player (X%)** and **To Management** breakdown
* *player mode only:* **Recipient** — the sender who received the money

#### Management Withdrawal / Deposit

* **Boss** — player name
* **Society** — job name
* **Amount** — value moved
* **New Balance** — society fund balance after the action

### Changing embed colours

Colours are set as decimal integers (Discord uses decimal, not hex). To convert: take your hex colour (e.g. `#00FF00`) and convert it to decimal (`65280`).

```
Config.LogColors = {
    invoicePaid    = 65352,    -- #00FF28 green
    invoiceCreated = 3447003,  -- #3498DB blue
    invoiceFailed  = 16711680, -- #FF0000 red
    withdraw       = 16776960, -- #FFFF00 yellow
    deposit        = 65352,    -- #00FF28 green
}
```

### Date format

The footer timestamp uses Lua's `os.date` format string. Examples:

| Format string       | Output example          |
| ------------------- | ----------------------- |
| `%d/%m/%Y [%X]`     | `08/05/2026 [14:32:01]` |
| `%Y-%m-%d %H:%M:%S` | `2026-05-08 14:32:01`   |
| `%B %d, %Y`         | `May 08, 2026`          |


---

# Agent Instructions: 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:

```
GET https://mohssins.gitbook.io/mohscriptsdocs/moh-billing/discord-webhook-logs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
