PRAW mentions not displaying when looping thru them

Question:

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.

Asked By: Maratonec

||

Answers:

Your code seems to be okay, i think you do not have any mentions to loop through.

Do you get print('loop') in stdout? If so then the above is the only reason you are not getting the logs.

Happy coding.

Answered By: Reshab Das

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()
Answered By: Maratonec
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.