Skip to content

Scripts Discord

Quadstronaut edited this page Jun 7, 2026 · 1 revision

Scripts: Discord

Scripts in Scripts/Discord/.


Send-RichEmbed.ps1

What it does: Posts a rich embed message to a Discord channel via a webhook URL.

Useful for sending formatted notifications from automation scripts, CI pipelines, or scheduled tasks.

Parameters:

Parameter Type Required Default Description
-WebhookUrl string Yes The Discord webhook URL for the target channel
-Title string Yes The embed title
-Description string Yes The embed body text
-Color int No 65280 Left-border color as a decimal integer (not hex string)
-Thumbnail string No URL for a thumbnail image shown in the embed
-Author hashtable No Author field: @{ name = "..."; icon_url = "..." }

Usage:

# Minimal — just title and description
.\Scripts\Discord\Send-RichEmbed.ps1 `
    -WebhookUrl "https://discord.com/api/webhooks/123456/abcdef" `
    -Title "Backup Complete" `
    -Description "Full backup of D:\Data finished successfully."

# With color and author
.\Scripts\Discord\Send-RichEmbed.ps1 `
    -WebhookUrl "https://discord.com/api/webhooks/123456/abcdef" `
    -Title "Alert" `
    -Description "Disk usage exceeded 90%." `
    -Color 16711680 `
    -Author @{ name = "Server Monitor"; icon_url = "https://example.com/icon.png" }

Color format:

Discord's API requires embed colors as decimal integers, not hex strings. Convert hex to decimal:

Color Hex Decimal
Green (default) #00FF00 65280
Red #FF0000 16711680
Blue #0000FF 255
Orange #FFA500 16753920
Yellow #FFFF00 16776960
# PowerShell hex-to-decimal conversion:
[int]"0xFF0000"   # returns 16711680

Requirements: PowerShell 3.0+ (uses Invoke-RestMethod). A valid Discord webhook URL.

How to get a webhook URL:

  1. Open Discord → Server Settings → Integrations → Webhooks.
  2. Click "New Webhook", configure the name and channel.
  3. Click "Copy Webhook URL".

Notes:

  • The bot username is hardcoded to 'PowerShell Bot' and the avatar is the official PowerShell logo from the PowerShell GitHub repo. Edit $payload to customize these.
  • Discord webhook rate limit: 30 requests per minute per webhook. For high-frequency notifications, batch messages or add a delay.
  • The -Thumbnail and -Author fields are optional embed components per the Discord embed structure. Fields (e.g., inline field rows) and footers are not implemented in this script — extend $embedObject to add them.

Troubleshooting:

  • Invoke-RestMethod returns HTTP 204 (No Content) on success — this is correct for Discord webhooks.
  • HTTP 400: Malformed payload — usually a missing required field or incorrect JSON structure. Check -Title and -Description are not empty.
  • HTTP 401: Invalid webhook URL.
  • HTTP 429: Rate limited. Add Start-Sleep between calls.

Clone this wiki locally