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...
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.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.