I'm creating a reddit bot. When I create a post that contains a image and a title. I want to automatically add a comment under that created post that contains a piece of text ("hello world").
I'm using python and praw.
I have looked at the documentation
But I couldnt manage to wrap my head around it and make it work.
This is the code I use to post a post with a title and a image.
reddit.subreddit(subreddit).submit_image(title, image_path)
How can I also add a comment to that created post?
You are looking at the documentation for an old version of PRAW (3.6.0), which has not been updated since 2016 at least. The latest documentation can be found here. Based on your usage of submit_image
, I guess you are using at least PRAW 6.1.0, since the method was added in that version.
The methods submit
, submit_image
, and submit_video
all return the newly created Submission
. All you have to do then is reply
to the Submission
like so:
my_post = reddit.subreddit(subreddit).submit_image(title, image_path)
my_post.reply("This is a comment.")
If you don't need to do anything with the post (and so don't need to store it in a variable), you could even do this in one line:
reddit.subreddit(subreddit).submit_image(title, image_path).reply("This is a comment.")