I'm trying to make a bot that replies whoever mentions it, but I want to put an if statement to check if the mentioning is a reply of a tweet (that originally mentioned my @)
This is my code -
import tweepy
import time
from datetime import datetime
# Connecting to Twitter API
client = tweepy.Client(bearer_token, api_key, api_secret, access_token, access_token_secret)
auth = tweepy.OAuth1UserHandler(api_key, api_secret, access_token, access_token_secret)
api = tweepy.API(auth)
# Message to reply with if someone mentions the bot
message = "Hi, Thank you so much for reaching TalkyTweety Out :) Please reply to continue this conversation. "
# Bot's unique ID
client_id = client.get_me().data.id
# This is so the bot only looks for the most recent tweets.
start_id = 1
initialisation_resp = client.get_users_mentions(client_id)
if initialisation_resp.data != None:
start_id = initialisation_resp.data[0].id
# Looking for mentions tweets in an endless loop
while True:
response = client.get_users_mentions(client_id, since_id=start_id)
# Reply Code
if response.data != None:
for tweet in response.data:
try:
print(tweet.text)
client.create_tweet(in_reply_to_tweet_id=tweet.id, text=message)
start_id = tweet.id
except Exception as error:
print(error)
# Delay (so the bot doesn't search for new tweets a bunch of times each second)
time.sleep(5)
I've tried using the resources from this Thread but it doesn't work. It simply doesn't executes - in_reply_to_status_id.