PowerShell script that polls the d2emu Terror Zone API and optionally posts alerts to a Discord channel via webhook.
Ex notifications:
- Defines an “alert list” of zone IDs you care about (
$d2rAlertZoneIds). - On a schedule (minute
00,05,30,35of each hour), calls the d2emu API for terror zone info. - If any current or next terror zone matches your alert list, it prints a message or (with
-SendToDiscord) sends it to Discord. - With
-DumpInfo, it prints/sends the current terror zone info ignoring the$d2rAlertZoneIdsfilter.
Edit the $d2rAlertZoneIds array in CheckTzAndAlertDiscord.ps1. Ex for keys/act bosses:
$d2rAlertZoneIds = @(
20, # "Forgotten Tower"
37, # "Catacombs 4"
73, # "Tal Rashas Chamber"
74, # "Arcane Sanctuary"
102, # "Durance of Hate 3"
108, # "Chaos Sanctuary"
123, # "Halls of Pain"
132 # "Worldstone Keep"
)- The numeric IDs come from the
$d2rZoneIdsmapping near the top of the script. - Keep this list to integers only.
The script reads required secrets from tz-bot.env placed next to CheckTzAndAlertDiscord.ps1.
- Rename
tz-bot.env.exampletotz-bot.env. - Fill in these required values in JSON:
{
"X_EMU_USERNAME": "<your d2emu username>",
"X_EMU_TOKEN": "<your d2emu token>",
"DISCORD_WEBHOOK_URL": "https://discord.com/api/webhooks/<id>/<token>"
}If any required key is missing, the script fails and prints what value is missing.
You must request API access from d2emu:
- Join their Discord: https://www.d2emu.com/about
- Then open #request-token and create a ticket.
- Copy the username/token into your
tz-bot.envfile.
- In Discord, open your server and choose the target channel.
- Channel Settings → Integrations → Webhooks → “New Webhook”.
- Copy the webhook URL into
DISCORD_WEBHOOK_URLintz-bot.env.
Run once to print the current and next terror zone(s):
pwsh -File .\CheckTzAndAlertDiscord.ps1 -DumpInfoSend the current and next terror zone(s) to Discord:
pwsh -File .\CheckTzAndAlertDiscord.ps1 -DumpInfo -SendToDiscordRun continuously (waits until the next query time and loops forever):
pwsh -File .\CheckTzAndAlertDiscord.ps1Run continuously and send alerts to Discord:
pwsh -File .\CheckTzAndAlertDiscord.ps1 -SendToDiscordUse -RunOnce to do a single poll + alert pass and then exit.
This is the best option when running from cron so you don’t end up with overlapping long-running processes.
Examples:
- One-time check (prints to console):
pwsh -File .\CheckTzAndAlertDiscord.ps1 -RunOnce
- One-time check (send alerts to Discord):
pwsh -File .\CheckTzAndAlertDiscord.ps1 -RunOnce -SendToDiscord
Run continuously and ignores filters, dumping the Current TZ when it changes:
pwsh -File .\CheckTzAndAlertDiscord.ps1 -DumpAllLoopThe script calculates the next poll time via GetNextQueryTime (currently :00, :05, :30, and :35 each hour).
Examples:
-
Linux
cron(every hour 8am 9pm at minute 00, 05, 30, 35 Sat/Sun):00,05,30,35 8-21 * * Sun,Sat pwsh -File /home/<username>/scripts/CheckTzAndAlertDiscord.ps1 -SendToDiscord -RunOnce -
Windows: use Task Scheduler to run
pwsh.exewith arguments like or run in console:-File "E:\src\d2r-tz-discord-hook\CheckTzAndAlertDiscord.ps1" -SendToDiscord- Ensure the runtime is set to indefinitely so it does not get terminated.