Documentation

Support

Triggers

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.
Read time 3 minutesLast updated 3 hours ago

Many game teams use Discord for community and live ops. Discord incoming 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.

Prerequisites

  • A Discord server with a channel where you want messages to appear.
  • A Unity project with Triggers enabled. Refer to Get started if you haven't set up Triggers yet.
  • Familiarity with webhook actions. Refer to Webhooks.

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:
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 so neither is exposed in the trigger configuration.
  1. In the Unity Dashboard, 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, 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:
    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:
    { "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. For richer messages, Discord also supports an
    embeds
    array. Refer to Discord's execute-webhook documentation 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).
  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.
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, where you can replay it.

Create the trigger via the API or CLI

To create the same trigger using the Triggers Admin API or the CLI, store
DISCORD_WEBHOOK_ID
and
DISCORD_WEBHOOK_TOKEN
in Secret Manager, then create the trigger:
{ "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