Praw 脚本抛出错误
Praw script throws an error
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'
subredit
是一个发电机。这意味着您必须迭代其结果。通过使用 for 循环,您可以像这样访问其结果:
for x in subreddit:
x.add_comment('Cat.')
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'
subredit
是一个发电机。这意味着您必须迭代其结果。通过使用 for 循环,您可以像这样访问其结果:
for x in subreddit:
x.add_comment('Cat.')