pythonpraw

PRAW mentions not displaying when looping thru them


I am trying to make a bot, that will reply when mentioned with PRAW API.

import praw
import time

print("Bot running..")
//login info


def replyFunc():
    print(reddit.inbox.mentions(limit=None))
    for mention in reddit.inbox.mentions(limit=None):
        print(f"{mention.author}\n{mention.body}\n")
        mention.reply("**test**")
        mention.read()

while True:
    replyFunc()
    print("Loop")
    time.sleep(2)

No errors printed and nothing is and print(f"{mention.author}\n{mention.body}\n") is not printed

Edit: when I get all inbox items using reddit.inbox.all(limit=None) code works well, but with it, program will register all messages in inbox not just mentions.


Solution

  • So, for me, the mentions function isn't working (maybe a PRAW bug) so I made a small workaround.

    def replyFunc():
    
    for mention in reddit.inbox.unread(limit=None):
            if "mention (u/botname)" in mention.body:
                print(f"{mention.author}\n{mention.body}\n")
                mention.reply("**test2**")
                mention.mark_read()