-1

我已经制作了一个机器人来回复追随者,只要他们用关键词给我打电话。但是回复只出现在我的帐户上。收到回复的人看不到回复或收到通知

import tweepy
import random
import time

CONSUMER_KEY = 'xxxxx'
CONSUMER_SECRET = 'xxxxx'
ACCESS_KEY = 'xx-xx'
ACCESS_SECRET = 'xxxx'

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)

max_tweets = 20

list_delirio = ['coisa escrita', 'yes']

list_isso = ['ok', 'nope']

list_acabou = ['bye', 'see you']

delirio = random.choice(list_delirio)
isso = random.choice(list_isso)
acabou = random.choice(list_acabou)


def get_id():
    with open('ultimoid.txt', 'r') as f:
        ultimoid = f.read()
    return ultimoid


def salva_id(novo_ultimo_id):
    with open('ultimoid.txt', 'w') as f:
        f.write(str(novo_ultimo_id))


def responde():
    ultimoid = get_id()
    ids_pegos = []
    time.sleep(20)
    try:
        for tweet in tweepy.Cursor(api.mentions_timeline, since_id=ultimoid).items(max_tweets):
            ids_pegos.append(tweet.id)
            user_name = tweet.user.screen_name
            status = api.get_status(tweet.id)
            if 'frota' in status.text.lower():
                api.update_status('@' + user_name + '\n hello...', in_reply_to_status_id=tweet.id, auto_populate_reply_metadata=True)
            elif 'hello' in status.text.lower():
                api.update_status('@' + user_name + '\n wtf!', in_reply_to_status_id=tweet.id, auto_populate_reply_metadata=True)
            elif 'delírio' in status.text.lower():
                api.update_status('@' + user_name + '\n' + delirio, in_reply_to_status_id=tweet.id, auto_populate_reply_metadata=True)
            elif 'é isso?' in status.text.lower():
                api.update_status('@' + user_name + '\n' + isso, in_reply_to_status_id=tweet.id, auto_populate_reply_metadata=True)
                time.sleep(6)
            else:
                api.update_status('@' + user_name + '\n' + acabou, in_reply_to_status_id=tweet.id, auto_populate_reply_metadata=True)
                time.sleep(6)
        salva_id(max(ids_pegos))
    except Exception:
        time.sleep(30)
        pass


if __name__ == '__main__':
    while True:
        responde()
        time.sleep(30)

我试图了解问题所在。我已经放了

in_reply_to_status_id=tweet.id, auto_populate_reply_metadata=True

正如文档所说,但仍然无法正常工作

4

1 回答 1

0

我找到了解决方案:

这条线status = api.get_status(tweet.id)不应该在那里。所以每个都status.text.lower()应该tweet.text.lower()

最重要的是,代码必须使用字符串而不是 Id 上的整数,所以每次tweet.id停留

推文.id_str

因此salva_id(max(ids_pegos))变为salva_id(ids_pegos[0])

于 2020-09-29T14:38:52.477 回答