停止Tweepy机器人回复循环

时间:2020-06-30 10:32:47

标签: python-3.x tweepy twitterapi-python

我是Python的新手,所以我现在所做的可能根本没有意义。我为此表示歉意。

当前,我遇到了麻烦,因为该机器人对提及内容的回复已经回复。我想防止它多次回答相同的提及。因此,我尝试使代码从已经回答的ID中检索最高的tweet ID,并将其更新为new_since_id的值。但这似乎不起作用。我写的是这样的:

import tweepy, time, logging, random

CONSUMER_KEY ="XXXXX"
CONSUMER_SECRET = "XXXXX"   
ACCESS_KEY = "XXXXX"    
ACCESS_SECRET = "XXXXX"

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)

api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)

mentions_tweets = api.mentions_timeline(tweet_mode='extended')
    for status in api.mentions_timeline():
        update_id = str(max(status.id))
        new_since_id = update_id

def roll_100d():

    for mentions_tweet in (mentions_tweets):
        if new_since_id == mentions_tweet.id and '[Dice]' in mentions_tweet.full_text():
            diceroll = str(random.randint(1,100))
            api.update_status('@' + mentions_tweet.user.screen_name + ' Your dice result is '+ diceroll + '.',
            in_reply_to_status_id = mentions_tweet.id)

while True:
    roll_100d()
    time.sleep(15)

有什么办法可以使它工作?我收到TypeError,但不知道如何解决。

0 个答案:

没有答案