Abhimanyu Sharma
Abhimanyu Sharma

Reputation: 903

unable to send image through discord webhooks

i created a method that takes a screenshot

def send_screenshot_to_discord(self):
        webhook=discord_webhooks.DiscordWebhooks("https://discord.com/api/webhooks/xyz")
        img=ImageGrab.grab()
        webhook.set_image(image=img)
        webhook.set_footer(text="img")
        webhook.send()

the result :

enter image description here

Upvotes: 0

Views: 4424

Answers (1)

Catgal
Catgal

Reputation: 718

Unfortunately, the discord_webhooks package you're using does not support file attachments, making it impossible to set the locally saved images or Pil-created images as embed images.

The way you set local images as embed images is by using attachment://image.png as the embed.set_image function's url argument, and since you cannot attach images, you can't do that.

Here is the FAQ from discord.py on how to set local images as embed images.

file = discord.File("path/to/my/image.png", filename="image.png")
embed = discord.Embed()
embed.set_image(url="attachment://image.png")
await channel.send(file=file, embed=embed)

Consider using discord_webhook or discord.py's webhook.

Upvotes: 1

Related Questions