admin管理员组文章数量:1333450
I am working on a GitHub Actions workflow that downloads a list of GIFs from various URLs and sends them to a Discord channel via a webhook. While the GIFs are being successfully downloaded and stored, the workflow is failing when trying to send the images to Discord.
The issue seems to occur after the images are downloaded, where I receive an error related to the curl command used to send the images to Discord. Despite the images being saved locally, the webhook seems to not process them correctly, causing the action to exit with an error.
Can you help me?
Code:
name: Send GIFs to Discord
on:
workflow_dispatch:
jobs:
send_gifs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Create the images.txt file (just for example)
run: |
echo ".gif" > images.txt
echo ".gif" >> images.txt
echo ".gif?cid=6c09b95222uwc8asta5froj2f8x5wqy2nf01qzj887wj2e4e&ep=v1_gifs_search&rid=giphy.gif&ct=g" >> images.txt
echo ":ANd9GcRa1o0IbXbQahK7bgr1X9egomrJxtihfsct2A&s" >> images.txt
echo ".gif?cid=6c09b952xxejdvjn3r5upcrzc1o23p0c5qot7krl4egj9pqa&ep=v1_gifs_search&rid=giphy.gif&ct=g" >> images.txt
echo ".gif" >> images.txt
- name: Read URLs from the file and download the images
run: |
i=0
while IFS= read -r url; do
echo "Downloading: $url"
if curl -L "$url" -o "image$i.gif"; then
echo "Image $i downloaded successfully."
((i++)) # Increment the counter only if the download was successful
else
echo "Error downloading image $i from $url"
fi
done < images.txt
echo "Total images downloaded: $i"
- name: Check if any images were downloaded
run: |
if [ $i -eq 0 ]; then
echo "No images were downloaded. Terminating workflow."
exit 1
fi
- name: Send the first image to Discord via Webhook
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
echo "Sending the first image: image0.gif to Discord"
# Add the curl command with the -v flag for detailed debug information
response=$(curl -X POST "$DISCORD_WEBHOOK" \
-H "Content-Type: multipart/form-data" \
-F "content=GIF sent via GitHub Actions" \
-F "[email protected]" \
-v) # Add the -v flag to see the full Discord response
# Show the full response from Discord
echo "Response from Discord:"
echo "$response"
# Check if the curl operation succeeded
if [ $? -ne 0 ]; then
echo "Error sending GIF to Discord."
exit 1
fi
本文标签: Sending image to Discord via GitHub Actions workflowStack Overflow
版权声明:本文标题:Sending image to Discord via GitHub Actions workflow - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742353172a2458895.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论