【问题标题】:automating adding comment to reddit when posting with praw使用 praw 发布时自动向 reddit 添加评论
【发布时间】:2020-05-04 10:46:10
【问题描述】:

我正在创建一个 reddit 机器人。当我创建一个包含图像和标题的帖子时。我想在包含一段文字(“hello world”)的已创建帖子下自动添加评论。

我正在使用 python 和 praw。

我看过文档

https://praw.readthedocs.io/en/v3.6.0/pages/code_overview.html?highlight=comment#praw.objects.Submission.add_comment

但我无法设法将其包裹起来并使其发挥作用。

这是我用来发布带有标题和图片的帖子的代码。

reddit.subreddit(subreddit).submit_image(title, image_path)

我怎样才能在创建的帖子中添加评论?

【问题讨论】:

  • 由于submit 似乎没有返回提交的帖子,您可能需要等待一小段时间(以允许帖子通过)然后从机器人帐户获取最新帖子并对此发表评论

标签: python bots reddit praw


【解决方案1】:

您正在查看旧版本 PRAW (3.6.0) 的文档,该文档至少自 2016 年以来未更新。最新的文档可以在here 找到。根据您对submit_image 的使用,我猜您至少使用的是PRAW 6.1.0,因为方法是added in that version

submitsubmit_imagesubmit_video 方法都返回新创建的Submission。你所要做的就是replySubmission,就像这样:

my_post = reddit.subreddit(subreddit).submit_image(title, image_path)
my_post.reply("This is a comment.")

如果您不需要对帖子执行任何操作(因此不需要将其存储在变量中),您甚至可以在一行中执行此操作:

reddit.subreddit(subreddit).submit_image(title, image_path).reply("This is a comment.")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-22
    • 2013-06-25
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 2014-03-06
    相关资源
    最近更新 更多