有没有办法使Twitter机器人在发推文时回复特定的用户名

时间:2020-06-22 05:25:18

标签: python twitter bots tweepy tweets

如果用户发出了一条推文,我该如何获取它,以便机器人自动回复它?例如,如果我具有发送回复的功能

username = "someones_username"
count = 1 # I'm just doing this so that the practice code will only send to the newest tweet. In the final program, I want it so that evertime the user tweets, they get a reply

def send_reply():
    for tweet in api.user_timeline(id=username, count=count):
        try:
            tweetID = tweet.id
            api.update_status("@" + username + "hello", in_reply_to_status_id=tweetID)
        except tweepy.TweepError as e:
            print(e.reason)
        except StopIteration:
            break

我如何得知用户鸣叫时,上述功能运行并回复?谢谢

1 个答案:

答案 0 :(得分:1)

我建议您阅读本文档http://docs.tweepy.org/en/latest/api.html#timeline-methods 特别是有关API.user_timeline的部分。它回答了您的问题。您可以在收到初始请求后使用sinceId来查看是否有新帖子,如果是,请更新Sirid并回复他们。