title: Python3 send a image .png into a Discord channel using webhook
body: <p>I have a python 3.6 script that generates a png image file and I simply want to post this image in a Discord channel at the end of the python script. How can I do so?</p>
  <p>It is a surprisingly challenging task as none of the following solutions seem to work</p>
  <ol>
  <li>Use CV2 to put an image in a json body. The OpenCV library installation is way to painful. Spend 1 hour and still cannot get</li>
  </ol>
  <p><code>import cv2</code></p>
  <p>done without an error message.  Simply give up on CV2.</p>
  <p><a href="https://stackoverflow.com/questions/50909569/unable-to-import-cv2-module-python-3-6">Unable to import cv2 module (Python 3.6)</a>
  <a href="https://stackoverflow.com/questions/64650877/install-of-opencv-python-headless-takes-a-long-time">Install of opencv-python-headless takes a long time</a>
  <a href="https://stackoverflow.com/questions/65620167/newbie-python-pycharm-and-anaconda-issues">Newbie Python, PyCharm and Anaconda issues</a></p>
  <pre><code>def send_image_to_discord(self, image_file, url):
  #   this version requires CV2 which is super painful to install
  
      
      # this function takes the image and send it to the Discord channel
  
      img = cv2.imread(image_file)
  
      string_img = base64.b64encode(cv2.imencode('.png', img)[1]).decode()
  
      req = {&quot;image&quot;: string_img}
  
      res = requests.post(url, json=req)
  
      return res
  
  URL = 'Discord channel webhook' 
  self.send_image_to_discord(image_file, URL)
  </code></pre>
  <ol start="2">
  <li><p>Use Discord.py but that is more for a BOT with await</p>
  <pre><code>async def send_image_to_discord(self, image_file, discord_channel_id):
  
       client = discord.Client()
  
       channel = client.get_channel(discord_channel_id)
  
       await channel.send('hello')
  
       await channel.send(file=discord.File(image_file))
  
  URL = 'discord channel id'
  self.send_image_to_discord(image_file, url)
  </code></pre>
  </li>
  </ol>
  <p>Any other ways? Thank you!</p>