Skip to content

Instantly share code, notes, and snippets.

@Jocadbz
Created December 7, 2025 22:43
Show Gist options
  • Select an option

  • Save Jocadbz/8ad7de68cb41f9f0d7c9358ebe7424e4 to your computer and use it in GitHub Desktop.

Select an option

Save Jocadbz/8ad7de68cb41f9f0d7c9358ebe7424e4 to your computer and use it in GitHub Desktop.
Little bash function to start a command and notify you on discord when it is finished through a webhook.
discord_notify() {
local WEBHOOK="YOUR_WEBHOOK_API"
local USER_ID="YOUR_USER_ID"
curl -s -H "Content-Type: application/json" \
-d "{\"content\": \"<@$USER_ID> Started\`\`\`bash\n$*\n\`\`\`\"}" \
"$WEBHOOK" > /dev/null
local START=$(date +%s)
eval "$@"
local EXIT_CODE=$?
local END=$(date +%s)
local DURATION=$((END - START))
if [ $EXIT_CODE -eq 0 ]; then
local EMOJI="Success"
local STATUS="SUCCESS"
else
local EMOJI="Failed"
local STATUS="FAILED (code $EXIT_CODE)"
fi
curl -s -H "Content-Type: application/json" \
-d "{\"content\": \"<@$USER_ID> $EMOJI **$STATUS** after ${DURATION}s\n\`\`\`bash\n$*\n\`\`\`\"}" \
"$WEBHOOK" > /dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment