Skip to content

Instantly share code, notes, and snippets.

@ashishjullia
Created October 28, 2023 19:58
Show Gist options
  • Save ashishjullia/eacc7ab7739b4e7baf6f5373af557995 to your computer and use it in GitHub Desktop.
Save ashishjullia/eacc7ab7739b4e7baf6f5373af557995 to your computer and use it in GitHub Desktop.
Shell script to send message to a discord channel using discord channel webhook
#!/bin/bash
# Replace with your Discord webhook URL
DISCORD_WEBHOOK_URL="<DISCORD_WEBHOOK_URL>"
# Fixed values
USERNAME="qbitorrent-pi4"
# AVATAR_URL="https://example.com/avatar.png"
MENTION_USER_ID="<MENTION_USER_ID>"
# Check if an argument is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <additional_text>"
exit 1
fi
# Get the additional text from the argument
ADDITIONAL_TEXT="$1"
# Construct the message
MESSAGE="<@$MENTION_USER_ID>\nDownloaded... $ADDITIONAL_TEXT"
# Construct the JSON payload
PAYLOAD=$(cat <<EOF
{
"username": "$USERNAME",
"content": "$MESSAGE"
}
EOF
)
# Send the message to Discord using curl
curl -X POST "$DISCORD_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment