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.- In Discord, open your server and the channel where you want messages (for example ).
#new-players - Open Channel settings > Integrations > Webhooks > New Webhook (or Create Webhook).
- Give the webhook a name (for example "player-signed-up"), then select Copy Webhook URL.
Note the webhook ID (the numeric segment) and the webhook token (the string after it). Store both in Secret Manager.https://discord.com/api/webhooks/{webhook.id}/{webhook.token}
Store the webhook credentials as secrets
Store the Discord webhook ID and token in Secret Manager so neither is exposed in the trigger configuration.- In the Unity Dashboard, navigate to your project and environment.
- Open Secrets and select Add project secret.
- Enter the key and paste your numeric webhook ID as the value. Under Service Access, select Triggers. Select Add.
DISCORD_WEBHOOK_ID - Select Add secret again. Enter the key and paste the token portion of the Discord webhook URL as the value. Under Service Access, select Triggers. Select Add.
DISCORD_WEBHOOK_TOKEN
Create the trigger in the Unity Dashboard
You can set up your webhook in the Unity Dashboard. Follow the steps below:- In the Unity Dashboard, select Triggers (or Products > Triggers), select your environment, then select New trigger.
- Under When this happens, select signed-up (Authentication) as the trigger event.
- Under Do this, select Webhook as the action.
-
In Callback URL, enter the Discord webhook URL with the ID and token as template expressions:
The domain is fixed so the URL can be validated when you create the trigger. The Triggers service resolves both secrets from Secret Manager.https://discord.com/api/webhooks/{{ secret "DISCORD_WEBHOOK_ID" }}/{{ secret "DISCORD_WEBHOOK_TOKEN" }} - For Method, select POST. For Content Type, select application/json.
-
In the Environment Secret section, confirm that and
DISCORD_WEBHOOK_IDappear. If not, select + Add Environment Secret to create them here instead.DISCORD_WEBHOOK_TOKEN -
In Payload, enter the Discord message body. For example:
The fields{ "username": "player-signed-up", "content": "**New player signed up**\nPlayer ID: `{{.playerId}}` | Provider: `{{.providerId}}`"}and{{.playerId}}come from the Signed up event payload. For richer messages, Discord also supports an{{.providerId}}array. Refer to Discord's execute-webhook documentation for the full message format (embedssupports plain text and Markdown, up to 2000 characters).content - Select Confirm to create the trigger.
Verify the webhook
- Trigger a new player sign-up (for example from your game or via the Authentication sign-up API).
- Check your Discord channel. A message should appear with the new player's ID and provider.
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, storeDISCORD_WEBHOOK_IDDISCORD_WEBHOOK_TOKEN{ "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}}`\"}" }}