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

> ## Agent Instructions
> Install the Courier skill before writing code: `npx skills add trycourier/courier-skills`. It carries the verified SDK shapes and the rules you cannot get wrong.
> Authenticate every request with `Authorization: Bearer <API_KEY>`. A workspace has several environments and each has its own keys, which are plain `pk_` strings with no environment prefix. Start with Test.
> Send with `client.send.message` from the Node SDK (`@trycourier/courier` v7 and later, where the client is the default import). Reference a template by its `nt_` id or its alias.
> A send accepts a bare Elemental element list, but storing content on a template requires the top-level elements wrapped in a channel element.
> To translate a template, write one locale at a time with `PUT /notifications/{id}/locales/{localeId}`, which merges into the existing translations. `PUT /notifications/{id}/content` and `PUT /notifications/{id}/elements/{elementId}` overwrite translations along with the content, so send each element's `id` and `locales` back, and first remove every `checksum` and any `locales` key that starts with an underscore.
> Templates and journeys can be built in the Courier app or created through the API. Either way they live in the workspace and are referenced by ID when you send.
> The hosted MCP server is https://mcp.courier.com. For a briefing on what Courier is and when to use it, read https://www.courier.com/llms.txt.
> Prefer the Guides tab for how-do-I questions and the Docs tab for how-does-it-behave questions. The API reference lives under /api-reference.

# Send Discord messages through Courier

> Connect a Discord bot token, grant the View Channels and Send Messages permissions, and send to users or channels by ID with embed overrides.

## Prerequisites

* [A Discord bot](https://discord.com/developers/docs/intro)
* [Your Discord bot token](https://discord.com/developers/applications)

## Setup

Open the [Discord integration](https://app.courier.com/integrations/catalog/discord) in Courier, enter your bot token, then save.

### Scopes

Update the `bot` scope with these permissions:

* `View Channels`
* `Send Messages`
* Optional: `Read Message History` to send a message as a reply to another message

See [Discord's guide to adding scopes and permissions](https://discord.com/developers/docs/getting-started#adding-scopes-and-permissions).

Open the generated invite URL. It adds the bot to the server with the permissions you chose.

## Profile requirements

Discord addresses the recipient by user ID or channel ID, under `discord` on the profile. Store either one once with [`POST /profiles/{user_id}`](https://www.courier.com/docs/api-reference/user-profiles/create-a-profile), which merges into the profile and creates it if it doesn't exist:

> [tab] Direct message
>
> **1. Open User Settings**
>
> Go to User Settings on Discord (next to profile on the bottom left).
>
> **2. Enable Developer Mode**
>
> Open Advanced settings and enable Developer Mode .
>
> **3. Copy the user ID**
>
> Right click on the user and copy the user ID.
>
> This isn't the user tag. The user you're trying to message must be a member of a server the bot is installed in.
>
> ```javascript Node.js highlight={3-5} theme={null}
> const profile = await client.profiles.create('user_123', {
>   profile: {
>     discord: {
>       user_id: '617099137532932107',
>     },
>   },
> });
> ```
>
> ```python Python highlight={4-6} theme={null}
> profile = client.profiles.create(
>     user_id="user_123",
>     profile={
>         "discord": {
>             "user_id": "617099137532932107",
>         },
>     },
> )
> ```
>
> ```bash cURL highlight={7-9} theme={null}
> curl --request POST \
>   --url https://api.courier.com/profiles/user_123 \
>   --header "Authorization: Bearer $COURIER_API_KEY" \
>   --header 'Content-Type: application/json' \
>   --data '{
>     "profile": {
>       "discord": {
>         "user_id": "617099137532932107"
>       }
>     }
>   }'
> ```
>
> ```ruby Ruby highlight={4-6} theme={null}
> profile = courier.profiles.create(
>   "user_123",
>   profile: {
>     discord: {
>       user_id: "617099137532932107"
>     }
>   }
> )
> ```
>
> ```go Go highlight={6-8} theme={null}
> profile, err := client.Profiles.New(
> 	context.TODO(),
> 	"user_123",
> 	courier.ProfileNewParams{
> 		Profile: map[string]any{
> 			"discord": map[string]any{
> 				"user_id": "617099137532932107",
> 			},
> 		},
> 	},
> )
> ```
>
> ```java Java highlight={4-5} theme={null}
> ProfileCreateParams params = ProfileCreateParams.builder()
>     .userId("user_123")
>     .profile(ProfileCreateParams.Profile.builder()
>         .putAdditionalProperty("discord", JsonValue.from(java.util.Map.of(
>             "user_id", "617099137532932107")))
>         .build())
>     .build();
> ProfileCreateResponse profile = client.profiles().create(params);
> ```
>
> ```php PHP highlight={2-4} theme={null}
> $profile = $client->profiles->create('user_123', profile: [
>   'discord' => [
>     'user_id' => '617099137532932107',
>   ],
> ]);
> ```
>
> ```csharp C# highlight={7-9} theme={null}
> ProfileCreateParams parameters = new()
> {
>     UserID = "user_123",
>     Profile = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(
>         """
>         {
>           "discord": {
>             "user_id": "617099137532932107"
>           }
>         }
>         """
>     ),
> };
> var profile = await client.Profiles.Create(parameters);
> ```
>
> ```bash CLI highlight={4} wrap theme={null}
> courier profiles create \
>   --api-key "$COURIER_API_KEY" \
>   --user-id user_123 \
>   --profile '{"discord":{"user_id":"617099137532932107"}}'
> ```
>
> ```text MCP theme={null}
> With Courier MCP, save the Discord user id 617099137532932107 on user_123.
> ```

> [tab] Channel
>
> **1. Open User Settings**
>
> Go to User Settings on Discord (next to profile on the bottom left).
>
> **2. Enable Developer Mode**
>
> Open Advanced settings and enable Developer Mode .
>
> **3. Copy the channel ID**
>
> Right click on the channel and copy the channel ID.
>
> The bot must be installed in the server to send to the channel.
>
> ```javascript Node.js highlight={3-5} theme={null}
> const profile = await client.profiles.create('user_123', {
>   profile: {
>     discord: {
>       channel_id: '768866348853383208',
>     },
>   },
> });
> ```
>
> ```python Python highlight={4-6} theme={null}
> profile = client.profiles.create(
>     user_id="user_123",
>     profile={
>         "discord": {
>             "channel_id": "768866348853383208",
>         },
>     },
> )
> ```
>
> ```bash cURL highlight={7-9} theme={null}
> curl --request POST \
>   --url https://api.courier.com/profiles/user_123 \
>   --header "Authorization: Bearer $COURIER_API_KEY" \
>   --header 'Content-Type: application/json' \
>   --data '{
>     "profile": {
>       "discord": {
>         "channel_id": "768866348853383208"
>       }
>     }
>   }'
> ```
>
> ```ruby Ruby highlight={4-6} theme={null}
> profile = courier.profiles.create(
>   "user_123",
>   profile: {
>     discord: {
>       channel_id: "768866348853383208"
>     }
>   }
> )
> ```
>
> ```go Go highlight={6-8} theme={null}
> profile, err := client.Profiles.New(
> 	context.TODO(),
> 	"user_123",
> 	courier.ProfileNewParams{
> 		Profile: map[string]any{
> 			"discord": map[string]any{
> 				"channel_id": "768866348853383208",
> 			},
> 		},
> 	},
> )
> ```
>
> ```java Java highlight={4-5} theme={null}
> ProfileCreateParams params = ProfileCreateParams.builder()
>     .userId("user_123")
>     .profile(ProfileCreateParams.Profile.builder()
>         .putAdditionalProperty("discord", JsonValue.from(java.util.Map.of(
>             "channel_id", "768866348853383208")))
>         .build())
>     .build();
> ProfileCreateResponse profile = client.profiles().create(params);
> ```
>
> ```php PHP highlight={2-4} theme={null}
> $profile = $client->profiles->create('user_123', profile: [
>   'discord' => [
>     'channel_id' => '768866348853383208',
>   ],
> ]);
> ```
>
> ```csharp C# highlight={7-9} theme={null}
> ProfileCreateParams parameters = new()
> {
>     UserID = "user_123",
>     Profile = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(
>         """
>         {
>           "discord": {
>             "channel_id": "768866348853383208"
>           }
>         }
>         """
>     ),
> };
> var profile = await client.Profiles.Create(parameters);
> ```
>
> ```bash CLI highlight={4} wrap theme={null}
> courier profiles create \
>   --api-key "$COURIER_API_KEY" \
>   --user-id user_123 \
>   --profile '{"discord":{"channel_id":"768866348853383208"}}'
> ```
>
> ```text MCP theme={null}
> With Courier MCP, save the Discord channel id 768866348853383208 on user_123.
> ```

Then send to `user_id` and Courier resolves the address.

For a one-off with no stored profile, pass it inline instead: `"to": { "discord": { "user_id": "617099137532932107" } }`.

> [card] [Send by user id](https://www.courier.com/docs/recipients/overview.md#send-by-user-id)
>
> The call in every language, and the rest of the profile object.

## Send to a recipient

> [tab] Send to user id
>
> Courier reads `discord` off the saved profile, so preferences apply and the value can change without touching this code.
>
> ```javascript Node.js highlight={4} theme={null}
> const { requestId } = await courier.send.message({
>   message: {
>     to: {
>       user_id: "user_123",
>     },
>     template: "nt_01kx4h2jdafq8bk9aftxak4b40",
>   },
> });
> ```
>
> ```python Python highlight={4} theme={null}
> response = client.send.message(
>     message={
>         "to": {
>             "user_id": "user_123",
>         },
>         "template": "nt_01kx4h2jdafq8bk9aftxak4b40",
>     },
> )
> ```
>
> ```bash cURL highlight={7} wrap theme={null}
> curl -X POST https://api.courier.com/send \
>   -H "Authorization: Bearer $COURIER_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "message": {
>       "to": {
>         "user_id": "user_123"
>       },
>       "template": "nt_01kx4h2jdafq8bk9aftxak4b40"
>     }
>   }'
> ```
>
> ```ruby Ruby highlight={4} theme={null}
> response = courier.send_.message(
>   message: {
>     to: {
>       user_id: "user_123"
>     },
>     template: "nt_01kx4h2jdafq8bk9aftxak4b40"
>   }
> )
> ```
>
> ```go Go highlight={5} theme={null}
> response, err := client.Send.Message(context.TODO(), courier.SendMessageParams{
> 	Message: courier.SendMessageParamsMessage{
> 		To: courier.SendMessageParamsMessageToUnion{
> 			OfUserRecipient: &shared.UserRecipientParam{
> 				UserID: courier.String("user_123"),
> 			},
> 		},
> 		Template: courier.String("nt_01kx4h2jdafq8bk9aftxak4b40"),
> 	},
> })
> ```
>
> ```java Java highlight={3} theme={null}
> SendMessageParams params = SendMessageParams.builder()
>     .message(SendMessageParams.Message.builder()
>         .to(UserRecipient.builder().userId("user_123").build())
>         .template("nt_01kx4h2jdafq8bk9aftxak4b40")
>         .build())
>     .build();
> SendMessageResponse response = client.send().message(params);
> ```
>
> ```php PHP highlight={4} theme={null}
> $response = $client->send->message(
>   message: [
>     'to' => [
>       'user_id' => 'user_123',
>     ],
>     'template' => 'nt_01kx4h2jdafq8bk9aftxak4b40',
>   ],
> );
> ```
>
> ```csharp C# highlight={5} theme={null}
> SendMessageParams parameters = new()
> {
>     Message = new()
>     {
>         To = new UserRecipient { UserID = "user_123" },
>         Template = "nt_01kx4h2jdafq8bk9aftxak4b40",
>     },
> };
>
> var response = await client.Send.Message(parameters);
> ```
>
> ```bash CLI highlight={3} wrap theme={null}
> courier send message \
>   --api-key "$COURIER_API_KEY" \
>   --message.to '{"user_id": "user_123"}' \
>   --message.template nt_01kx4h2jdafq8bk9aftxak4b40
> ```
>
> ```text MCP theme={null}
> With Courier MCP, send my template to user_123 by email.
> ```

> [tab] Send to `discord`
>
> Pass it inline instead and nothing is stored. Swap this `to` object into the call on the other tab.
>
> ```javascript Node.js highlight={5-7} theme={null}
> const { requestId } = await courier.send.message({
>   message: {
>     // A provider recipient is a profile field, so it sits outside the typed union.
>     to: {
>       discord: {
>         user_id: "617099137532932107",
>       },
>     } as any,
>     template: "nt_01kx4h2jdafq8bk9aftxak4b40",
>   },
> });
> ```
>
> ```python Python highlight={4-6} theme={null}
> response = client.send.message(
>     message={
>         "to": {
>             "discord": {
>                 "user_id": "617099137532932107",
>             },
>         },
>         "template": "nt_01kx4h2jdafq8bk9aftxak4b40",
>     },
> )
> ```
>
> ```bash cURL highlight={7-9} wrap theme={null}
> curl -X POST https://api.courier.com/send \
>   -H "Authorization: Bearer $COURIER_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "message": {
>       "to": {
>         "discord": {
>           "user_id": "617099137532932107"
>         }
>       },
>       "template": "nt_01kx4h2jdafq8bk9aftxak4b40"
>     }
>   }'
> ```
>
> ```ruby Ruby highlight={4-6} theme={null}
> response = courier.send_.message(
>   message: {
>     to: {
>       discord: {
>         user_id: "617099137532932107"
>       }
>     },
>     template: "nt_01kx4h2jdafq8bk9aftxak4b40"
>   }
> )
> ```
>
> ```go Go highlight={2-4} theme={null}
> // A provider recipient is a profile field, so it sits outside the typed union.
> to := param.Override[shared.UserRecipientParam](
> 	json.RawMessage(`{"discord": {"user_id": "617099137532932107"}}`),
> )
>
> response, err := client.Send.Message(context.TODO(), courier.SendMessageParams{
> 	Message: courier.SendMessageParamsMessage{
> 		To: courier.SendMessageParamsMessageToUnion{OfUserRecipient: &to},
> 		Template: courier.String("nt_01kx4h2jdafq8bk9aftxak4b40"),
> 	},
> })
> ```
>
> ```java Java highlight={3-4} theme={null}
> // A provider recipient is a profile field, so it sits outside the typed union.
> UserRecipient to = UserRecipient.builder()
>     .putAdditionalProperty("discord", JsonValue.from(Map.of(
>             "user_id", "617099137532932107")))
>     .build();
>
> client.send().message(SendMessageParams.builder()
>     .message(SendMessageParams.Message.builder()
>         .to(to)
>         .template("nt_01kx4h2jdafq8bk9aftxak4b40")
>         .build())
>     .build());
> ```
>
> ```php PHP highlight={4-6} theme={null}
> $response = $client->send->message(
>   message: [
>     'to' => [
>       'discord' => [
>         'user_id' => '617099137532932107',
>       ],
>     ],
>     'template' => 'nt_01kx4h2jdafq8bk9aftxak4b40',
>   ],
> );
> ```
>
> ```csharp C# highlight={3-5} theme={null}
> // A provider recipient is a profile field, so it sits outside the typed union.
> UserRecipient to = UserRecipient.FromRawUnchecked(
>     JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(
>         """{"discord": {"user_id": "617099137532932107"}}"""
>     )
> );
>
> var response = await client.Send.Message(new() { Message = new() { To = to, Template = "nt_01kx4h2jdafq8bk9aftxak4b40" } });
> ```
>
> ```bash CLI highlight={3} wrap theme={null}
> courier send message \
>   --api-key "$COURIER_API_KEY" \
>   --message.to '{"discord": {"user_id": "617099137532932107"}}' \
>   --message.template nt_01kx4h2jdafq8bk9aftxak4b40
> ```
>
> ```text MCP theme={null}
> With Courier MCP, send my template to the Discord user 617099137532932107.
> ```

## Overrides

[How overrides work](https://www.courier.com/docs/send/overrides.md#how-overrides-work) covers the two levels and which one wins.

A provider override changes what Courier sends to Discord's [Create Message](https://discord.com/developers/docs/resources/channel#create-message) endpoint. Overrides are deep-merged into the request. Fields you set replace their counterparts, and everything you leave out is still sent. For example, add an embed.

```javascript Node.js highlight={5-7,10-19} theme={null}
const { requestId } = await courier.send.message({
  message: {
    template: "nt_01kx4h2jdafq8bk9aftxak4b40",
    to: {
      discord: {
        channel_id: "768866348853383208",
      },
    },
    providers: {
      discord: {
        override: {
          body: {
            embed: {
              title: "Hello, Embed!",
              description: "This is an embedded message.",
            },
          },
        },
      },
    },
  },
});
```

```python Python highlight={5-7,10-19} theme={null}
response = client.send.message(
    message={
        "template": "nt_01kx4h2jdafq8bk9aftxak4b40",
        "to": {
            "discord": {
                "channel_id": "768866348853383208",
            },
        },
        "providers": {
            "discord": {
                "override": {
                    "body": {
                        "embed": {
                            "title": "Hello, Embed!",
                            "description": "This is an embedded message.",
                        },
                    },
                },
            },
        },
    },
)
```

```bash cURL highlight={8-10,13-22} wrap theme={null}
curl -X POST https://api.courier.com/send \
  -H "Authorization: Bearer $COURIER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": {
      "template": "nt_01kx4h2jdafq8bk9aftxak4b40",
      "to": {
        "discord": {
          "channel_id": "768866348853383208"
        }
      },
      "providers": {
        "discord": {
          "override": {
            "body": {
              "embed": {
                "title": "Hello, Embed!",
                "description": "This is an embedded message."
              }
            }
          }
        }
      }
    }
  }'
```

```ruby Ruby highlight={5-7,10-19} theme={null}
response = courier.send_.message(
  message: {
    template: "nt_01kx4h2jdafq8bk9aftxak4b40",
    to: {
      discord: {
        channel_id: "768866348853383208"
      }
    },
    providers: {
      discord: {
        override: {
          body: {
            embed: {
              title: "Hello, Embed!",
              description: "This is an embedded message."
            }
          }
        }
      }
    }
  }
)
```

```go Go highlight={4-6,14-23} theme={null}
// This provider addresses the recipient with fields outside the typed
// UserRecipient model, so pass the recipient as raw JSON.
to := param.Override[shared.UserRecipientParam](json.RawMessage(`{
  "discord": {
    "channel_id": "768866348853383208"
  }
}`))

response, err := client.Send.Message(context.TODO(), courier.SendMessageParams{
	Message: courier.SendMessageParamsMessage{
		To: courier.SendMessageParamsMessageToUnion{OfUserRecipient: &to},
		Template: courier.String("nt_01kx4h2jdafq8bk9aftxak4b40"),
		Providers: shared.MessageProvidersParam{
			"discord": shared.MessageProvidersTypeParam{
				Override: map[string]any{
					"body": map[string]any{
						"embed": map[string]any{
							"title": "Hello, Embed!",
							"description": "This is an embedded message.",
						},
					},
				},
			},
		},
	},
})
```

```java Java highlight={6-8,12-19} theme={null}
SendMessageParams params = SendMessageParams.builder()
    .message(SendMessageParams.Message.builder()
        // This provider addresses the recipient with fields outside the
        // typed UserRecipient model, so pass them as additional properties.
        .to(UserRecipient.builder()
            .putAdditionalProperty("discord", JsonValue.from(java.util.Map.of(
                "channel_id", "768866348853383208"
            )))
            .build())
        .template("nt_01kx4h2jdafq8bk9aftxak4b40")
        .providers(MessageProviders.builder()
            .putAdditionalProperty("discord", JsonValue.from(java.util.Map.of("override", java.util.Map.of(
                    "body", java.util.Map.of(
                        "embed", java.util.Map.of(
                            "title", "Hello, Embed!",
                            "description", "This is an embedded message."
                        )
                    )
                ))))
            .build())
        .build())
    .build();
SendMessageResponse response = client.send().message(params);
```

```php PHP highlight={5-7,10-19} theme={null}
$response = $client->send->message(
  message: [
    'template' => 'nt_01kx4h2jdafq8bk9aftxak4b40',
    'to' => [
      'discord' => [
        'channel_id' => '768866348853383208',
      ],
    ],
    'providers' => [
      'discord' => [
        'override' => [
          'body' => [
            'embed' => [
              'title' => 'Hello, Embed!',
              'description' => 'This is an embedded message.',
            ],
          ],
        ],
      ],
    ],
  ],
);
```

```csharp C# highlight={11-13,21-38} theme={null}
SendMessageParams parameters = new()
{
    Message = new()
    {
        // This provider addresses the recipient with fields outside the
        // typed UserRecipient model, so build it from raw JSON.
        To = UserRecipient.FromRawUnchecked(
            JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(
                """
                {
                  "discord": {
                    "channel_id": "768866348853383208"
                  }
                }
                """
            )
        ),
        Template = "nt_01kx4h2jdafq8bk9aftxak4b40",
        Providers = new Dictionary<string, MessageProvidersType>()
        {
            {
                "discord",
                new()
                {
                    Override = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(
                        """
                        {
                          "body": {
                            "embed": {
                              "title": "Hello, Embed!",
                              "description": "This is an embedded message."
                            }
                          }
                        }
                        """
                    ),
                }
            },
        },
    },
};

var response = await client.Send.Message(parameters);
```

```bash CLI highlight={3,5} wrap theme={null}
courier send message \
  --api-key "$COURIER_API_KEY" \
  --message.to '{"discord": {"channel_id": "768866348853383208"}}' \
  --message.template nt_01kx4h2jdafq8bk9aftxak4b40 \
  --message.providers '{"discord": {"override": {"body": {"embed": {"title": "Hello, Embed!", "description": "This is an embedded message."}}}}}'
```

```text MCP theme={null}
With Courier MCP, send my template to Discord channel 768866348853383208 with a body override.
```

## Provider details

```text theme={null}
discord
```

Courier recommends routing to the channel. Naming this key in `routing.channels` instead is supported, and sends through just this provider.

> [card] [Send to a specific provider](https://www.courier.com/docs/send/send-to-a-provider.md)
>
> When that is worth doing, and what you give up: failover, channel priority, and providers you add later.

> [card] [Set a send rate limit](https://www.courier.com/docs/integrations/send-rate-limits.md)
>
> Control how fast Courier sends to this provider. Sends above the rate are queued.
