Reply to tweets from a specific user with Tweepy

Asked

Viewed 38 times

0

Using the library Tweepy, I’m trying to make a bot that reply in all tweets of only one specific user, the problem is that the bot is giving reply not only in the tweet but in everyone that retweet or responds the tweet.

auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

id = "1234"
user = api.get_user(id)


def randomize(status):
    tweet = status.split()
    shuffle(tweet)
    tweet_string = " ".join(tweet)
    return tweet_string


class Reply(tweepy.StreamListener):
    def on_status(self, status):
        print(status.text)
        api.update_status("@" + status.user.screen_name + " " + randomize(status.text), in_reply_to_status_id=status.id)


listener = Reply()
stream = tweepy.Stream(auth=api.auth, listener=listener)
stream.filter(follow=[id])

Library documentation Tweepy: https://docs.tweepy.org/en/stable/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.