Search code examples
pythonredditpraw

Including the username of comment above in reply by bot with PRAW


I'm developing a Reddit bot with PRAW, and I want to have the username of the person the bot is replying to in it's reply.

for comment in comments:
    comment_text = comment.body.lower()
    isMatch = any(string in comment_text for string in words_to_match)
    if comment.id not in cache and isMatch:
        print("Comment match found;" + comment.id)
        comment.reply('Hello + author.name')
        print("Reply successful!")
        cache.append(comment.id)

However, this does not work and it simply replies as text, as expected. Is it possible to reply with the username of the comment, followed by more text?


Solution

  • You can get the author as a string of a comment object by

    str(comment.author)