使用PRAW获取新帖子的视频url并将其发送到discord服务器(PRAW,discord.py)

2024-06-09 13:21:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在discord.py bot中发出命令,将附加的图像或视频发送到reddit中的帖子。 但是,当一篇文章带有图片时,一切都很好。。。当文章包含视频时,结果如下:

enter image description here

现在我有这个:

@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

没有回溯,因为我没有收到任何错误


Tags: urlnew视频titlecount文章randompost
1条回答
网友
1楼 · 发布于 2024-06-09 13:21:09

Discord的API不允许在嵌入中使用自定义视频,如this other question所示。只要看看函数名,它是set_image。如果你想把视频放在那里,也许把它转换成gif就行了

相关问题 更多 >