How to find out the name of Redditor in PRAW?

Viewed 262

How do I find out the name of a Redditor in PRAW from a comment he made. For example, If a user comments something with the bot's keyword, they will reccive a PM. To send this the redditor's name must be obtained. I have tried using the following syntax but it doesnt work and shows an error message.

for comment in subreddit.stream.comments():
    if keyphrase in comment.body:
        plebman = comment.author
        reddit.redditor(plebman).message("TEST", "BOT TESTING")

this error message appears

plebman = comment.author
                      ^
TabError: inconsistent use of tabs and spaces in indentation

iI there any function to do so in PRAW ?

1 Answers

Update: I found this command in the PRAW documentation, it can get the name of the Author from the comments. The previous method worked as well, but it was stored as an unknow data type called 'redditor'. This method stores the value as a string eliminating the roadblock, I experienced before.

Then

for comment in subreddit.stream.comments():
    if keyphrase in comment.body:
        plebman = comment.author
        reddit.redditor(plebman).message("TEST", "BOT TESTING")

Now (Change in 3rd line)

for comment in subreddit.stream.comments():
    if keyphrase in comment.body:
        plebman = comment.author.name
        reddit.redditor(plebman).message("TEST", "BOT TESTING")

Or to summarise

username = comment.author.name

this way the name is stored as a string and can be used easily.

Related