import praw
import time
r = praw.Reddit(user_agent = "A bot by /u/")
r.login()
print("Logging in...")
cache = []
def run_bot():
print("Grabbing subreddit...")
subreddit = r.get_subreddit("test").get_new(limit=1)
print("The subreddit selected was /r/Test")
subreddit.add_comment('Cat.')
while True:
run_bot()
time.sleep(10)
我正在尝试使用短语 Cat。制作一个评论新提交内容的机器人,但我收到此错误:
Traceback (most recent call last):
File "C:\Users\Julian\Desktop\bot.py", line 19, in <module>
run_bot()
File "C:\Users\Julian\Desktop\bot.py", line 15, in run_bot
subreddit.add_comment('Cat.')
AttributeError: 'generator' object has no attribute 'add_comment'
答案 0 :(得分:0)
subredit
是一个发电机。这意味着你必须迭代它的结果。通过使用for循环,您可以访问其结果:
for x in subreddit:
x.add_comment('Cat.')