How to get parent comment from message?
I have a bot that responds to user mentions. I need to load the parent comment of the comment that mentioned my bot. How can I do this?
This is the error I get:
'Message' object has no attribute 'parent'
Posted Feb 28, 2020, 12:29 AM UTC
Parent should be a function rather than an attribute. Try
parent().I still get the error
Please post your code
This is the relevant code
for i in reddit.inbox.stream():
try:
comment = i.parent()
comment.refresh()
If you're streaming the entire inbox, you'll be getting both username mentions as well as regular messages. But messages don't have a parent. You need to either fetch only mentions or check whether the object is a comment or message before calling parent.