Created
October 28, 2023 19:58
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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