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.
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.
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()
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.
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.
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()