# Use case sample: Notify a Discord channel when players sign up

> Post messages to a Discord channel using a webhook trigger when players sign up with Authentication.

Many game teams use [Discord](https://discord.com) for community and live ops. Discord [incoming webhooks](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) lets you post to a channel from an external URL. This sample shows how to use a Triggers webhook to post to Discord every time a player signs up so your team can monitor new sign-ups in real time.

For webhook configuration and template syntax, refer to [Webhooks](/triggers/webhooks.md).

## Prerequisites

* A Discord server with a channel where you want messages to appear.
* A Unity project with Triggers enabled. Refer to [Get started](../../getting-started) if you haven't set up Triggers yet.
* Familiarity with webhook actions. Refer to [Webhooks](/triggers/webhooks.md).

## Get a Discord webhook URL

Create an incoming webhook in your Discord server and note its URL structure.

1. In Discord, open your server and the channel where you want messages (for example `#new-players`).
2. Open **Channel settings** > **Integrations** > **Webhooks** > **New Webhook** (or **Create Webhook**).
3. Give the webhook a name (for example "player-signed-up"), then select **Copy Webhook URL**.

Discord webhook URLs have the following format:

```text
https://discord.com/api/webhooks/{webhook.id}/{webhook.token}
```

Note the webhook ID (the numeric segment) and the webhook token (the string after it). Store both in Secret Manager.

## Store the webhook credentials as secrets

Store the Discord webhook ID and token in [Secret Manager](/services/secret-manager.md) so neither is exposed in the trigger configuration.

1. In the [Unity Dashboard](https://cloud.unity.com), navigate to your project and environment.
2. Open **Secrets** and select **Add project secret**.
3. Enter the key `DISCORD_WEBHOOK_ID` and paste your numeric webhook ID as the value. Under **Service Access**, select **Triggers**. Select **Add**.
4. Select **Add secret** again. Enter the key `DISCORD_WEBHOOK_TOKEN` and paste the token portion of the Discord webhook URL as the value. Under **Service Access**, select **Triggers**. Select **Add**.

## Create the trigger in the Unity Dashboard

You can set up your webhook in the Unity Dashboard. Follow the steps below:

1. In the [Unity Dashboard](https://cloud.unity.com), select **Triggers** (or **Products** > **Triggers**), select your environment, then select **New trigger**.

2. Under **When this happens**, select signed-up (Authentication) as the trigger event.

3. Under **Do this**, select **Webhook** as the action.

4. In **Callback URL**, enter the Discord webhook URL with the ID and token as template expressions:

   ```text
   https://discord.com/api/webhooks/{{ secret "DISCORD_WEBHOOK_ID" }}/{{ secret "DISCORD_WEBHOOK_TOKEN" }}
   ```

   The domain is fixed so the URL can be validated when you create the trigger. The Triggers service resolves both secrets from Secret Manager.

5. For **Method**, select POST. For **Content Type**, select application/json.

6. In the **Environment Secret** section, confirm that `DISCORD_WEBHOOK_ID` and `DISCORD_WEBHOOK_TOKEN` appear. If not, select **+ Add Environment Secret** to create them here instead.

7. In **Payload**, enter the Discord message body. For example:

   ```json
   {
     "username": "player-signed-up",
     "content": "**New player signed up**\nPlayer ID: `{{.playerId}}` | Provider: `{{.providerId}}`"
   }
   ```

   The fields `{{.playerId}}` and `{{.providerId}}` come from the [Signed up event payload](../../manage-events/supported-ugs-events#signed-up). For richer messages, Discord also supports an `embeds` array. Refer to [Discord's execute-webhook documentation](https://discord.com/developers/docs/resources/webhook#execute-webhook) for the full message format (`content` supports plain text and Markdown, up to 2000 characters).

8. Select **Confirm** to create the trigger.

## Verify the webhook

1. Trigger a new player sign-up (for example from your game or via the [Authentication sign-up API](https://services.docs.unity.com/player-auth/v1/#tag/player-authentication/operation/signUp)).
2. Check your Discord channel. A message should appear with the new player's ID and provider.

> **Tip:**
>
> To trigger a sign-up without running your game, go to **Cloud Code** > **Scripts**   in the Unity Dashboard, open any script, and then, on the **Run Code** tab, select **Generate** in the **Player ID** section. This creates a new anonymous player and triggers a signed-up event. For more information, refer to [Generate a test Player ID](/cloud-code/scripts/how-to-guides/test-run.md#generate-a-test-player-id).

If no message appears, open the trigger in the Unity Dashboard and select **View Trigger Logs** to check for delivery errors. If a delivery fails after retries, the event is added to the [dead letter queue](/triggers/tutorials/manage-dlq/dead-letter-queue.md), where you can replay it.

## Create the trigger via the API or CLI

To create the same trigger using the [Triggers Admin API](https://services.docs.unity.com/triggers-admin/v1/) or the [CLI](../define-triggers/cli), store `DISCORD_WEBHOOK_ID` and `DISCORD_WEBHOOK_TOKEN` in [Secret Manager](/services/secret-manager.md), then create the trigger:

```json
{
  "name": "discord-new-player",
  "eventType": "com.unity.services.player-auth.signed-up.v1",
  "actionType": "webhook",
  "actionUrn": "urn:ugs:webhook",
  "webhook": {
    "url": "https://discord.com/api/webhooks/{{ secret \"DISCORD_WEBHOOK_ID\" }}/{{ secret \"DISCORD_WEBHOOK_TOKEN\" }}",
    "method": "POST",
    "headers": {
      "Content-Type": "application/json"
    },
    "payloadTemplate": "{\"username\": \"player-signed-up\", \"content\": \"**New player signed up**\\nPlayer ID: `{{.playerId}}` | Provider: `{{.providerId}}`\"}"
  }
}
```

## Additional resources

* [Webhooks](/triggers/webhooks.md)
* [Dead letter queue](/triggers/tutorials/manage-dlq/dead-letter-queue.md)
* [Define triggers in the Unity Dashboard](../define-triggers/unity-dashboard)
* [Secret Manager](/services/secret-manager.md)
