3

There seems to be little to no support so far for the newer versions of Tweepy and the new Twitter API and I would like to reply to tweets based on mention of my account but I'm not sure how to retrieve a tweet id that mentions me so I can reply to it.

mention_id = 1


# The actual bot
while True:
    mentions = tweepy.Client.get_users_mentions(mention_id) 

    for mention in mentions:
        print("Mention tweet found")
        print(f"{mention.author.screen_name} - {mention.text}")
        mention_id = mention.id

        if mention.in_reply_to_status_id is True:
                try:
                    print("Attempting to reply...")
                    response = client.create_tweet(text='tweet response text here', 
                    in_reply_to_tweet_id=mention_id)
                    print(response)
                    print("Successfully replied :)")
                except Exception as exc:
                    print(exc)
    time.sleep(90) 
Mohammad
  • 43
  • 4
  • What is the error you are seeing here? You probably need to add some expansions to the `get_users_mentions` call in order to access the author information. I'd start out by seeing what data is actually in the mentions objects you are iterating through. There is also a Discussions section on the Tweepy GitHub repo, as well as a dedicated Tweepy Discord server - lots of support available. – Andy Piper Feb 02 '22 at 11:32

1 Answers1

0

This should give you the id.

getattr(mention[0], 'id')

The '[0]' is for which tweet it has fetched. E.g. if you've fetched 5, just put anything between 0-4 there.

If you want the text, replace " 'id' " with " 'text' "

XLVII
  • 101
  • 4