1
votes

I am playing around with a discord.py bot, I have pretty much everything working that I need (at this time), but I can't for the life of me figure out how to embed a YouTube video using Embed().

I don't really have any code to post per-say, as none of it has worked correctly.

Note: I've tried searching everywhere (here + web), I see plenty of info on embedding images which works great.

I do see detail in the discord API for embedding video, as well as the API Documentation for discord.py; but no clear example of how to pull it off.

I am using commands (the module I am working on as a cog)

Any help would be greatly appreciated.

Environment:

  • Discord.py Version: 0.16.11
  • Python: 3.5.2
  • Platform: OS X
  • VirtualEnv: Yes
3

3 Answers

4
votes

What you are asking for is unfortunately impossible, since Discord API does not allow you to set custom videos in embeds.

1
votes

Only form of media you can embed is images and gifs. It’s not possible to embed a video

0
votes

I dug into this problem a bit and inspected what's going on behind the scenes but ultimately the reason seems to be that discord internally generates a proxy_url to prevent IP grabbing and the embeded video that you see in the channel comes from the proxy_url.

If you inspect the embed that discord generates when you paste a link, it is not a rich embed, but a video embed. You can actually create this video embed yourself but likely due to security reasons you cannot send it without it getting mangled.

Inspected object:

{'type': 'video',
 'url': 'https://example.com/video.mp4',
 'video': {'height': 480,
           'proxy_url': 'https://images-ext-1.discordapp.net/external/Tr36h2z0bxXh1JF-DYH6igRBj9SClhe_b1sxIF8CvgA/https://example.com/video.mp4',
           'url': 'https://example.com/video.mp4',
           'width': 480}}

How to create a custom video embed:

TestVideoEmbed = {}
TestVideoEmbed['type'] = 'video'
TestVideoEmbed['url'] = 'https://example.com/video.mp4'
VideoDict = {}
VideoDict['height'] = 480
VideoDict['proxy_url'] = 'https://images-ext-1.discordapp.net/external/Tr36h2z0bxXh1JF-DYH6igRBj9SClhe_b1sxIF8CvgA/https://example.com/video.mp4'
VideoDict['url'] = 'https://example.com/video.mp4'
VideoDict['width'] = 480
TestVideoEmbed['video'] = VideoDict
CreatedEmbed = discord.embeds.Embed.from_dict(TestVideoEmbed)

Despite the fact that you can create the video embed yourself, if you send it, somewhere along the line the discord api will turn it into a rich embed which lacks the proper fields and turns into this:

{'type': 'rich',
 'url': 'https://example.com/video.mp4'}

Ultimately, the 2 limiting factors are that we would need to be able to create the proxy_url through the api and have the final video embed be sent to the client software as a video embed without being converted.