【问题标题】:Is there a way to make it that a twitter bot will reply to a specific username if they tweet有没有办法让推特机器人在推特时回复特定的用户名
【发布时间】:2020-10-11 22:22:28
【问题描述】:

如果用户发送了一条推文,我怎样才能得到它,以便机器人自动回复它?例如,如果我有这个发送回复的函数

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

我怎样才能知道当用户发推文时,上述函数会运行并回复他们?谢谢

【问题讨论】:

    标签: python twitter bots tweepy tweets


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-01-13
      • 2013-05-24
      • 2021-03-29
      • 2010-10-12
      • 2017-05-15
      • 2011-03-12
      • 2021-04-17
      • 1970-01-01
      • 2021-10-05
      相关资源
      最近更新 更多