最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Sending image to Discord via GitHub Actions workflow - Stack Overflow

programmeradmin0浏览0评论

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
发布评论

评论列表(0)

  1. 暂无评论