使用 PRAW 获取新 post 视频的 url 并将其发送到 discord 服务器(praw,discord.py)
Getting the url of a video of a new post using PRAW and send it to a discord server (praw, discord.py)
我正在尝试在我的 discord.py 机器人中发出命令,将图像或视频附加到 reddit 中的 post。
但是,当 post 与图像一起使用时,一切正常......当 post 包含视频时,结果如下:
现在我有这个:
@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
没有回溯,因为我没有收到任何错误...
Discord 的 API 不允许您在嵌入中使用自定义视频,如 this other question 所示。看看这个函数的名字,它是set_image
。如果你想在那里放一个视频,也许把它转换成 gif 就可以了。
作为一种丑陋的解决方法,您可以让它自己将 link 粘贴到嵌入下方。这样 discord 后端将正确生成 proxy_url 并且可以从消息中播放视频。
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)
我正在尝试在我的 discord.py 机器人中发出命令,将图像或视频附加到 reddit 中的 post。 但是,当 post 与图像一起使用时,一切正常......当 post 包含视频时,结果如下:
现在我有这个:
@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
没有回溯,因为我没有收到任何错误...
Discord 的 API 不允许您在嵌入中使用自定义视频,如 this other question 所示。看看这个函数的名字,它是set_image
。如果你想在那里放一个视频,也许把它转换成 gif 就可以了。
作为一种丑陋的解决方法,您可以让它自己将 link 粘贴到嵌入下方。这样 discord 后端将正确生成 proxy_url 并且可以从消息中播放视频。
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)