> For the complete documentation index, see [llms.txt](https://crypto-chief.gitbook.io/chief-event-stream/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://crypto-chief.gitbook.io/chief-event-stream/sinks/discord.md). Agents can also search and read this documentation through its [MCP server](https://crypto-chief.gitbook.io/chief-event-stream/~gitbook/mcp).

# Discord

## Discord

A `discord` sink posts each matched event to a Discord channel webhook (`https://discord.com/api/webhooks/<id>/<token>?wait=true`). Each message is escaped `content` text of up to `1,900` characters (Unicode code points), with user, role and `@everyone` mentions turned off.

### Before you start

1. In your Discord server, open **Channel Settings** → **Integrations** → **Webhooks**, create a webhook, and copy its URL (`https://discord.com/api/webhooks/<webhook_id>/<webhook_token>`).
2. Check the URL host and query string:
   * Only `https://discord.com` on port `443` with two path segments after `/api/webhooks/` is accepted. Legacy or alternate hosts (`discordapp.com`, `ptb.discord.com`, `canary.discord.com`) return `422` `DESTINATION_FORBIDDEN`.
   * Query parameters other than `?wait=true` (such as `?thread_id=...`) and `#` fragments return `422` `DESTINATION_FORBIDDEN`. Pass the bare URL or add `?wait=true`. EventStream adds `?wait=true` when the URL has no query, so Discord returns the created message `id`.

#### **Create a Discord sink**

<mark style="color:green;">`POST`</mark> `https://api-eventstream.crypto-chief.com/v1/sinks/create`

**Headers**

| Name            | Value                                                                                                                        |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Content-Type    | `application/json`                                                                                                           |
| Merchant        | Your Merchant ID                                                                                                             |
| X-CC-Timestamp  | Unix time in seconds                                                                                                         |
| X-CC-Nonce      | A new random value for every request                                                                                         |
| X-CC-Signature  | [Request signature](https://crypto-chief.gitbook.io/chief-event-stream/getting-started/authentication.md)                    |
| Idempotency-Key | **Required.** [Format](https://crypto-chief.gitbook.io/chief-event-stream/getting-started/authentication.md#idempotency-key) |

**Body**

Unknown fields return `400` `UNKNOWN_FIELD`.

| Name                      | Type    | Required | Description                                                                                                                                                                                                                                                        |
| ------------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `kind`                    | string  | true     | Must be `"discord"`.                                                                                                                                                                                                                                               |
| `config`                  | object  | true     | Configuration.                                                                                                                                                                                                                                                     |
| `config.format`           | string  | true     | Message layout; must be `"compact"`.                                                                                                                                                                                                                               |
| `config.label`            | string  | false    | Optional display label, `0`–`100` characters. No default stored.                                                                                                                                                                                                   |
| `config.rate_per_second`  | integer | false    | Events per second for this sink, `1`–`20`, default `20`. A project's notification sinks send one request at a time; see [Ordering, retries, and auto-pause](https://crypto-chief.gitbook.io/chief-event-stream/sinks/overview.md#ordering-retries-and-auto-pause). |
| `config.enabled`          | boolean | false    | Default `true`. With `false`, unsent deliveries stay `"queued"` and `status` stays `"active"`; see [`config.enabled`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/sinks.md#create-a-sink).                                                    |
| `credentials`             | object  | true     | Write-only; never returned. `credentials_meta.webhook_url.last4` in `sinks/get` is `null`.                                                                                                                                                                         |
| `credentials.webhook_url` | string  | true     | Discord webhook URL (`^https://`, up to `2,048` characters, matching `https://discord.com/api/webhooks/<id>/<token>` with optional `?wait=true`).                                                                                                                  |

```json
{
  "kind": "discord",
  "config": {
    "format": "compact",
    "label": "Discord security alerts",
    "rate_per_second": 5
  },
  "credentials": {
    "webhook_url": "https://discord.com/api/webhooks/123456789012345678/abcdefghijklmnopqrstuvwxyz0123456789"
  }
}
```

**Response**

{% tabs %}
{% tab title="201" %}

```json
{
  "ok": true,
  "data": {
    "sink_id": "019a0000-0000-7000-8000-000000000001",
    "kind": "discord",
    "status": "active",
    "secret": null,
    "secret_version": 0,
    "config": {
      "format": "compact",
      "label": "Discord security alerts",
      "rate_per_second": 5
    }
  },
  "request_id": "019a0000-0000-7000-8000-000000000099"
}
```

{% endtab %}

{% tab title="422" %}

```json
{
  "ok": false,
  "error": "DESTINATION_FORBIDDEN",
  "msg": "destination is forbidden by egress policy",
  "request_id": "019a0000-0000-7000-8000-000000000099",
  "details": {
    "field": "credentials.webhook_url"
  }
}
```

{% endtab %}

{% tab title="429" %}

```json
{
  "ok": false,
  "error": "PROJECT_LIMIT_EXCEEDED",
  "msg": "sink limit reached",
  "request_id": "019a0000-0000-7000-8000-000000000099",
  "details": {}
}
```

{% endtab %}
{% endtabs %}

### What arrives

EventStream sends `POST https://discord.com/api/webhooks/<id>/<token>?wait=true` with `Content-Type: application/json; charset=utf-8` and `User-Agent: CryptoChief-EventStream/1`.

* **Payload structure:** JSON object with `content` and `"allowed_mentions": {"parse": []}`. Lines follow the [message layout](https://crypto-chief.gitbook.io/chief-event-stream/sinks/overview.md#message-layout).
* **Escaping and mention neutralization:** control characters and Unicode bidirectional override characters are removed from field values; `\n` and `\t` inside values become spaces. The Markdown characters `` ` ``, `*`, `_`, `~`, `|`, `>`, `[`, and `]` inside values are escaped with a backslash. In `@everyone`, `@here`, `<@`, `<#`, and `<&`, a zero-width space (`\u200b`) is inserted, so on-chain strings cannot trigger mentions.
* **Truncation:** if `content` exceeds `1,900` characters, its end is replaced with `\n...\npayload_in_journal: true` and the `journal` line. Fetch the full event with [`events/get`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/events.md) by `event_id`.

Example Discord webhook request body for a confirmed `ETH_MAINNET` `USDC` `transfer.token` event:

```json
{
  "content": "[CryptoChief EventStream] transfer.token (confirmed)\nevent_id: 019a0000-0000-7000-8000-000000000011\nnetwork: ETH\\_MAINNET\nsubscription_id: 019a0000-0000-7000-8000-000000000003\nsequence: 42\noccurred_at: 2026-10-27T00:00:00.000Z\ntx_hash: 0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\ntransfer: 0x0000000000000000000000000000000000000002 -> 0x0000000000000000000000000000000000000001\namount: 125.5 USDC\ndata: amount={\"decimals\":6,\"raw\":\"125500000\",\"scale\":null}, asset={\"contract\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"decimals\":6,\"id\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"kind\":\"token\",\"standard\":\"erc20\",\"symbol\":\"USDC\",\"token\\_id\":null}, direction=in, from=0x0000000000000000000000000000000000000002, source={\"destination\\_tag\":null,\"kind\":\"log\",\"memo\":null,\"path\":\"log/7/erc20\",\"source\\_tag\":null,\"success\":true}, to=0x0000000000000000000000000000000000000001, utxo=null\njournal: https://app-data.crypto-chief.com/project/3f2a1b4c-5d6e-7f80-9a1b-2c3d4e5f6071/event-stream?event_id=019a0000-0000-7000-8000-000000000011",
  "allowed_mentions": {
    "parse": []
  }
}
```

### Retries and errors

With `?wait=true`, Discord returns HTTP `200` and the created message as JSON. A delivery succeeds only when Discord responds with HTTP `200`–`299` and a non-empty string `id`.

* **Retried (`transient`, up to `12` attempts over `24` hours):** network or timeout errors (`10`-second attempt limit), HTTP `408`, `425`, `429`, `500`–`599`, and interrupted or `> 16 KiB` response bodies. See [Retries and Ordering](https://crypto-chief.gitbook.io/chief-event-stream/webhooks/retries-and-ordering.md).
* **`Retry-After`:** on HTTP `429` and `503`, EventStream takes the delay from the `Retry-After` header, or from the `retry_after` JSON field (seconds, rounded up with `ceil`) when the header is missing. The delay is clamped to `[1s, 21600s]`.
* **Permanent failures (no retries; delivery moves to `dead`):**
  * HTTP `401` or `403` (invalid webhook token): pauses the **entire sink** with `pause_reason: "destination_auth"`.
  * HTTP `404` or `410` (deleted webhook or channel): pauses the **entire sink** with `pause_reason: "destination_gone"`.
  * HTTP `400` or `422`: pauses **only that `(subscription_id, sink_id)` lane** (`"destination_rejected"`), unless aggregate failures trigger whole-sink `"failures"`.
  * HTTP `300`–`399` or HTTP `200`–`299` without a non-empty `id` (such as `204 No Content`): pauses the **entire sink** with `pause_reason: "destination_rejected"`.
* **How to resume:** set a new `webhook_url` with [`sinks/update`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/sinks.md#update-a-sink) if needed, then call [`sinks/resume`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/sinks.md#resume-a-sink) with `mode: "drain"` (or `mode: "skip"` with `acknowledged_gap: true`).

### Duplicates

Discord webhooks do not deduplicate `POST` requests. If the response is lost after Discord creates the message, the retry posts it again. A Discord bot that reads the channel should deduplicate by the `event_id: <uuidv7>` line in `content`.

### Test delivery

Calling [`sinks/test`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/sinks.md) with `{"sink_id": "<uuidv7>", "sample_type": "system.test"}` posts a `content` message with `network: SYSTEM`, `stage: confirmed`, `message: EventStream test`, and `event_id` set to the test `delivery_id`:

```
[CryptoChief EventStream] system.test (confirmed)
event_id: 019a0000-0000-7000-8000-000000000002
network: SYSTEM
occurred_at: 2026-10-27T00:00:00.000Z
message: EventStream test
data: generated\_at=2026-10-27T00:00:00.000Z, message=EventStream test, sink\_id=019a0000-0000-7000-8000-000000000001
journal: https://app-data.crypto-chief.com/project/3f2a1b4c-5d6e-7f80-9a1b-2c3d4e5f6071/event-stream?event_id=019a0000-0000-7000-8000-000000000002
```

### What it costs

An acknowledged Discord message costs a channel fee of `1,000` credits (`$0.0001`) on top of the base event fee. Failed attempts, throttled events and `sinks/test` cost `0` credits. See [Billing](https://crypto-chief.gitbook.io/chief-event-stream/getting-started/billing.md).

### Example

`request()` is defined in [Authentication](https://crypto-chief.gitbook.io/chief-event-stream/getting-started/authentication.md). Both `sinks/create` and `sinks/test` require an `Idempotency-Key`.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
import crypto from "node:crypto";

const sink = await request(
  "sinks/create",
  {
    kind: "discord",
    config: {
      format: "compact",
      label: "Discord security alerts",
      rate_per_second: 5,
    },
    credentials: {
      webhook_url:
        "https://discord.com/api/webhooks/123456789012345678/abcdefghijklmnopqrstuvwxyz0123456789",
    },
  },
  crypto.randomUUID()
);

const test = await request(
  "sinks/test",
  {
    sink_id: sink.sink_id,
    sample_type: "system.test",
  },
  crypto.randomUUID()
);

console.log(sink.sink_id, test.delivery_id);
```

{% endtab %}

{% tab title="PHP" %}

```php
$sink = request(
    'sinks/create',
    [
        'kind' => 'discord',
        'config' => [
            'format'          => 'compact',
            'label'           => 'Discord security alerts',
            'rate_per_second' => 5,
        ],
        'credentials' => [
            'webhook_url' => 'https://discord.com/api/webhooks/123456789012345678/abcdefghijklmnopqrstuvwxyz0123456789',
        ],
    ],
    bin2hex(random_bytes(16))
);

$test = request(
    'sinks/test',
    [
        'sink_id'     => $sink['sink_id'],
        'sample_type' => 'system.test',
    ],
    bin2hex(random_bytes(16))
);

echo $sink['sink_id'] . ' ' . $test['delivery_id'] . "\n";
```

{% endtab %}

{% tab title="GO" %}

```go
sink, err := request("sinks/create", map[string]any{
	"kind": "discord",
	"config": map[string]any{
		"format":          "compact",
		"label":           "Discord security alerts",
		"rate_per_second": 5,
	},
	"credentials": map[string]any{
		"webhook_url": "https://discord.com/api/webhooks/123456789012345678/abcdefghijklmnopqrstuvwxyz0123456789",
	},
}, rand.Text())
if err != nil {
	panic(err)
}

test, err := request("sinks/test", map[string]any{
	"sink_id":     sink["sink_id"],
	"sample_type": "system.test",
}, rand.Text())
if err != nil {
	panic(err)
}

fmt.Println(sink["sink_id"], test["delivery_id"])
```

{% endtab %}

{% tab title="Python" %}

```python
import secrets

sink = request(
    "sinks/create",
    {
        "kind": "discord",
        "config": {
            "format": "compact",
            "label": "Discord security alerts",
            "rate_per_second": 5,
        },
        "credentials": {
            "webhook_url": "https://discord.com/api/webhooks/123456789012345678/abcdefghijklmnopqrstuvwxyz0123456789",
        },
    },
    secrets.token_hex(16),
)

test = request(
    "sinks/test",
    {
        "sink_id": sink["sink_id"],
        "sample_type": "system.test",
    },
    secrets.token_hex(16),
)

print(sink["sink_id"], test["delivery_id"])
```

{% endtab %}

{% tab title="curl" %}

```bash
sink=$(request sinks/create \
  '{"kind":"discord","config":{"format":"compact","label":"Discord security alerts","rate_per_second":5},"credentials":{"webhook_url":"https://discord.com/api/webhooks/123456789012345678/abcdefghijklmnopqrstuvwxyz0123456789"}}' \
  "$(openssl rand -hex 16)")

sink_id=$(jq -r '.sink_id' <<< "$sink")

request sinks/test \
  "{\"sink_id\":\"$sink_id\",\"sample_type\":\"system.test\"}" \
  "$(openssl rand -hex 16)"
```

{% endtab %}
{% endtabs %}
