> For the complete documentation index, see [llms.txt](https://organized-chaos.gitbook.io/organized-chaos-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://organized-chaos.gitbook.io/organized-chaos-docs/quackmobil/discord-logging.md).

# Discord logging

A staff log of takeoffs, and of takeoffs that were refused, in a Discord channel.

Quackmobil can post to a Discord channel of your staff who takes off in a duck, and who tried to without permission. It is off until you switch it on.

`Config.Discord` is in `config_server.lua`, next to `config.lua`.

```lua
Config.Discord = {
    Enabled = false,
    Webhook = '',        -- better: set the quackmobil_discord_webhook convar
    Username = '',
    AvatarUrl = '',
    Events = { Start = true, FlightDenied = true, Flight = false },
    DeniedCooldown = 30,
    Identifiers = false,
    FlushMs = 3000,
    MaxQueue = 100,
}
```

## Switching it on

1. In Discord, open the settings of the channel the log should go to, then **Integrations**, **Webhooks** and **New Webhook**, and copy the webhook URL.
2. Put the URL in your `server.cfg`, as shown below.
3. Set `Enabled = true` in `config_server.lua`.
4. Restart the server so the new line in `server.cfg` is read.

```cfg
set quackmobil_discord_webhook "https://discord.com/api/webhooks/..."
```

{% hint style="danger" %}
The webhook URL is a secret. Anyone who has it can post to your channel.
{% endhint %}

`config.lua` is sent to every player. `config_server.lua` is loaded on the server only, so the URL is safe there or in the convar, and must never go into `config.lua`. The resource does not print it either, not even in an error message.

## What is posted

Only events set to `true` in `Events` are posted.

| Event          | What the post says                                                                                         | Default |
| -------------- | ---------------------------------------------------------------------------------------------------------- | ------- |
| `Start`        | The resource has started: whether flight mode is on, who may fly, and whether simple mode is on            | `true`  |
| `FlightDenied` | A player tried to take off without permission: who, in which duck, and where                               | `true`  |
| `Flight`       | Every takeoff: who, in which duck, and where. This is a lot of messages on a server where everyone may fly | `false` |

`DeniedCooldown` is the number of seconds before the same player's next refused takeoff is posted again. A player who keeps pressing the key appears once, not once per press.

Who may fly is set in `Config.Flight`. See [Commands and permissions](/organized-chaos-docs/quackmobil/commands-and-permissions.md).

## Who the players are

Players are named with their name and server id. `Identifiers = true` adds every player's licence and their Discord account, as a mention, under the name.

{% hint style="warning" %}
Licences and Discord accounts are personal data. Turn `Identifiers` on only for a channel that just your staff can read, and only if your policy allows it.
{% endhint %}

## Delivery

| Option      | Default | Meaning                                                         |
| ----------- | ------- | --------------------------------------------------------------- |
| `Username`  | `''`    | The name the posts appear under. Empty uses the webhook's own   |
| `AvatarUrl` | `''`    | The picture the posts appear with. Empty uses the webhook's own |
| `FlushMs`   | `3000`  | How often the collected messages are posted, in milliseconds    |
| `MaxQueue`  | `100`   | How many messages wait at most while Discord cannot be reached  |

Messages are not sent one by one. They are collected and posted together, up to ten in one post. If Discord cannot be reached, the messages wait and are sent later. When more than `MaxQueue` are waiting, the oldest are dropped, and the next post says how many were lost. A problem with Discord never affects the ducks.

## Keeping it through an update

An update replaces `config_server.lua` together with the rest of the folder. Keep a copy of it along with `config.lua`, or keep the URL in the convar, which an update does not touch.
