Posting an embedded link with preview to Discord using Python Webhooks

Viewed 2568

I want to post a link to discord using Python and Webhooks, posting a news link. That link should automatically get rendered as in the picture below, showing the headline and the picture of the article and maybe some of the article text as in this example below which is using IFTTT webhooks to post. But since there are rate limits using ifttt i want to post using the commandline automatically. But i can only get it to post the url, or headline, but cannot get it to embed the picture of the article or the snippet of text of the article that you see in the example below. Can someone help me figure this out? I tried a lot of combinations using the "embed" JSON. I am just not able to get it to show the same way.

How it SHOULD look like

Here is my code, basically copied from 3.

data["username"] = "TFnews"
#data["payload_json"] = {"content":"headlinelink", "embed": {"title":       "Hello, Embed!", "description": "This is an embedded message." }}

#leave this out if you dont want an embed
data["embeds"] = []
embed = {}
#for all params, see https://discordapp.com/developers/docs/resources/channel#embed-object
#embed["description"] = ""
#embed["title"] = headline
#embed["url"] = headlinelink
#embed["embeds"]= { "url": "https://upload.wikimedia.org/wikipedia/commons/3/38/4-Nature-Wallpapers-2014-1_ukaavUI.jpg" }
#embed["image"]= { "proxy_url": "https://www.bloomberg.com/news/articles/2020-06-10/fed-puts-floor-under-bond-buying-sees-zero-rates-through-2022?srnd=premium-europe" }
embed["rich"] = headlinelink
#embed["thumbnail"] = { "url": "https://upload.wikimedia.org/wikipedia/commons/3/38/4-Nature-Wallpapers-2014-1_ukaavUI.jpg" }
data["embeds"].append(embed)

result = requests.post(url, data=json.dumps(data), headers={"Content-Type": "application/json"})

try:
    result.raise_for_status()
except requests.exceptions.HTTPError as err:
    print(err)
else:
    print("Payload delivered successfully, code {}.".format(result.status_code))

I tried all of the different options, but the only result i get is this

This is how it looks.

I am following these guides:

https://gist.github.com/Bilka2/5dd2ca2b6e9f3573e0c2defe5d3031b2

https://discord.com/developers/docs/resources/channel#embed-object-embed-thumbnail-structure

https://birdie0.github.io/discord-webhooks-guide/structure/embed/description.html

https://discord.com/developers/docs/resources/channel#embed-object

0 Answers
Related