> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Discord

> Client-mode REST API connector for a curated Discord API v10 slice: execute incoming webhooks, create channel messages with embeds, plus user/channel/gateway bot helpers

Technical Preview

## Overview

A client-mode connector for a **curated messaging** slice of the [Discord API v10](https://discord.com/developers/docs/reference):

| Catalog connector event | Entity / path | Notes |
| - | - | - |
| POST webhooks/\{id}/\{token} | `POST /webhooks/{webhook_id}/{webhook_token}` | Incoming webhook; path credentials; embeds OK |
| POST channels/\{id}/messages | `POST /channels/{channel_id}/messages` | Bot token; `content` and/or `embeds[]` |
| GET users/@me (smoke) | `GET /users/@me` | Bot credential check |
| GET channels/\{id} | `GET /channels/{channel_id}` | Channel lookup |
| GET gateway/bot | `GET /gateway/bot` | Bot gateway URL + limits |

Default `BASE_ADDRESS` is `https://discord.com/api/v10`. Topics use `messaging/discord/<object>/<verb>`.

> [!NOTE]
>
> Bot REST methods send `Authorization: Bot {token}`. Incoming webhook execute uses **only** the webhook id and token in the path — do not send a Bot header on that event. Prefer Hub secrets. Discord returns **429** with `retry_after` under rate limits. Gateway WebSocket / Interactions inbound → MQTT is out of scope for this client-mode package. Status remains blocked until an authenticated live smoke succeeds.

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
# Coreflux REST_API template — Discord API v10
# Auth: Bot {value.json.bot_token} on Bot REST; webhook path credentials on Executewebhook
# BASE_ADDRESS: https://discord.com/api/v10

DEFINE ROUTE DiscordRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://discord.com/api/v10"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT Getmyuser
        WITH SOURCE_TOPIC "messaging/discord/user/get-me"
        WITH DESTINATION_TOPIC "messaging/discord/user/get-me/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/users/@me"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bot {value.json.bot_token}"
    ADD EVENT Getchannel
        WITH SOURCE_TOPIC "messaging/discord/channel/get"
        WITH DESTINATION_TOPIC "messaging/discord/channel/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/channels/{value.json.channel_id}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bot {value.json.bot_token}"
    ADD EVENT Createmessage
        WITH SOURCE_TOPIC "messaging/discord/message/create"
        WITH DESTINATION_TOPIC "messaging/discord/message/create/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/channels/{value.json.channel_id}/messages"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bot {value.json.bot_token}"
        WITH BODY "{payload}"
    ADD EVENT Executewebhook
        WITH SOURCE_TOPIC "messaging/discord/webhook/execute"
        WITH DESTINATION_TOPIC "messaging/discord/webhook/execute/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/webhooks/{value.json.webhook_id}/{value.json.webhook_token}?wait={value.json.wait}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
        WITH BODY "{payload}"
    ADD EVENT Getbotgateway
        WITH SOURCE_TOPIC "messaging/discord/gateway/bot"
        WITH DESTINATION_TOPIC "messaging/discord/gateway/bot/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/gateway/bot"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bot {value.json.bot_token}"
```

## Events

| Event | Method | Endpoint | Request topic | Response topic |
| - | - | - | - | - |
| Getmyuser | GET | `/users/@me` | `messaging/discord/user/get-me` | `messaging/discord/user/get-me/response` |
| Getchannel | GET | `/channels/{channel_id}` | `messaging/discord/channel/get` | `messaging/discord/channel/get/response` |
| Createmessage | POST | `/channels/{channel_id}/messages` | `messaging/discord/message/create` | `messaging/discord/message/create/response` |
| Executewebhook | POST | `/webhooks/{webhook_id}/{webhook_token}` | `messaging/discord/webhook/execute` | `messaging/discord/webhook/execute/response` |
| Getbotgateway | GET | `/gateway/bot` | `messaging/discord/gateway/bot` | `messaging/discord/gateway/bot/response` |

## Auth

1. Create a Discord application + bot in the [Developer Portal](https://discord.com/developers/applications) and copy the bot token. Invite the bot to a lab guild with `Send Messages` (and related) permissions.
2. Set connector `BASE_ADDRESS` to `https://discord.com/api/v10`.
3. For Bot REST events, pass `bot_token` on the MQTT payload so `Authorization: Bot {value.json.bot_token}` resolves.
4. For incoming webhooks, create a channel webhook and pass `webhook_id` + `webhook_token` (optional `wait`); do **not** send a Bot Authorization header on Executewebhook.
5. Store secrets in Hub / `GET SECRET "DISCORD_BOT_TOKEN"`. Never commit real credentials.
6. Successful `GET /users/@me` returns **HTTP 200** with a user JSON object. `POST .../messages` returns **200**. Webhook execute returns **204** (`wait` false/omitted) or **200** (`wait=true`).

## Example payloads

**getMyUser:**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "bot_token": "YOUR_DISCORD_BOT_TOKEN"
}
```

**createMessage:**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "bot_token": "YOUR_DISCORD_BOT_TOKEN",
  "channel_id": "123456789012345678",
  "content": "Coreflux alarm: vibration above threshold — Zone A",
  "embeds": [
    {
      "title": "Zone A vibration",
      "description": "RMS exceeded limit",
      "color": 15158332
    }
  ]
}
```

**executeWebhook:**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "webhook_id": "YOUR_WEBHOOK_ID",
  "webhook_token": "YOUR_WEBHOOK_TOKEN",
  "wait": "true",
  "content": "Coreflux smoke",
  "embeds": [
    {
      "title": "Factory alert",
      "description": "Line 3 stopped"
    }
  ]
}
```

## Install

1. The template ships with the broker. List it with `-listTemplates` or fetch it from the Hub catalog.
2. Deploy with `-addRoute` from `DiscordRestApi.lot` (not `hub-metadata.lot`).

## See also

* [REST API Connectors](/latest/lot-language/routes/rest-api-routes)
* [REST API Apps](/latest/lot-language/routes/rest-api-apps)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.