<@ULVA73B9P> Is it possible to send an alert on di...
# ask-marvin
l
@Marvin Is it possible to send an alert on discord when prefect deployment or flow crash ? or not success ?
m
thought for 243.0 seconds
Yes — in Prefect 3.x you can send Discord alerts when a flow/deployment fails, crashes, times out, or otherwise doesn’t succeed. You do this with a Discord Webhook block + an Automation that triggers on flow-run events. Quick setup 1) Create a Discord webhook - In Discord: Server Settings > Integrations > Webhooks > New Webhook - Copy the webhook URL (it contains a webhook ID and token) 2) Create a Discord Webhook block in Prefect - In the Prefect UI: Blocks > + > Discord Webhook, paste the webhook ID and token, name it (e.g., discord-notifications) - Or via code:
Copy code
from prefect.blocks.notifications import DiscordWebhook

DiscordWebhook(
    webhook_id="YOUR_WEBHOOK_ID",
    webhook_token="YOUR_WEBHOOK_TOKEN",
    botname="Prefect Bot",     # optional
    include_image=True         # optional
).save("discord-notifications", overwrite=True)
Docs: DiscordWebhook block 3) Create an Automation to send the notification - In the Prefect UI: Automations > + New Automation - Trigger: Event, Reactive - Expect events for “not success”, e.g.: - prefect.flow-run.Failed - prefect.flow-run.Crashed - prefect.flow-run.TimedOut - prefect.flow-run.Cancelled - (Optional) Filter to a specific deployment/flow with match fields - Action: Send notification - Select your Discord block (e.g., discord-notifications) - Subject: e.g., Flow failed: {{ event.resource.name }} - Body:
Copy code
Event: {{ event.event }}
      Flow: {{ event.resource.name }}
      Run ID: {{ event.resource.id }}
      Occurred: {{ event.occurred }}
Docs: Creating automations, Event triggers Notes - To alert on success, add prefect.flow-run.Completed. - To scope to a specific deployment, add a match in the trigger (e.g., by deployment name). - If you’re on Prefect 2.x, the approach is different; I’d recommend upgrading to 3.x for Automations. Would you like this to fire for every flow in your workspace, or only specific deployments? And are you on Prefect Cloud or OSS? I can tailor the exact trigger filters for you.