'Getting the url of a video of a new post using PRAW and send it to a discord server (praw, discord.py)
I'm trying to make a command in my discord.py bot that send the image or the video attacched to a post in reddit. But, when a post is with an Image, all works fine... when the post contains a video, that's the results:
for now I have this:
@client.command()
async def meme(ctx):
subreddits = ['memesITA','yesyesyesyesno','nonononoyes','technicallythetruth','WatchPeopleDieInside','Wellthatsucks','hmmm']
probs = [1,2,3,4,5,6,7,8,9,10]
choice = random.choice(subreddits)
choice_num = random.choice(probs)
count = 0
new_messages = choice.new(limit=10)
for post in new_messages:
if count == choice_num:
img_url = post.url
title = post.title
em = discord.Embed(title=title)
em.set_image(url=img_url)
await ctx.send(embed=em)
break
count = count + 1
There is no traceback because I don't receive any error...
Solution 1:[1]
Discord's API doesn't let you use custom videos in embeds, as seen in this other question. Just look at the function's name, it's set_image
. If you want to place a video there, maybe converting it to gif will work.
Solution 2:[2]
As an ugly workaround you can just have it paste the link on its own below the embed. This way the discord backend will properly generate a proxy_url and the video will be playable from the message.
if hasattr(submission, 'media') and submission.media and 'reddit_video' in submission.media:
url = safe_get(submission.media, 'reddit_video', 'fallback_url')
await channel.send(embed=meme)
new_msg = await channel.send(content=url)
else:
meme.set_image(url=submission.url)
new_msg = await channel.send(content=None, embed=meme)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Parasol Kirby |
Solution 2 | 0xKate |