its nothing big from selenium import webdriver from selenium.webdriver.common.by import By import time
target_username = "thecheshirechatbot" # Username to monitor (no @) my_username = "johnny_dapple_seed" # Your Threads username (no @) auto_reply = "π€‘" # The emoji to reply with
replied_to = set()
driver = webdriver.Chrome()
driver.get("https://www.threads.net") input("π’ Please log in manually, then press Enter here to continue...")
driver.get(f"https://www.threads.net/@{my_username}") time.sleep(5)
print(f"π Monitoring comments on posts by @{my_username} for comments from @{target_username}...")
while True: try: # Find all post links posts = driver.find_elements(By.CSS_SELECTOR, "a[href*='/@'][href*='/post/']") post_urls = list(set([p.get_attribute("href") for p in posts]))
for post_url in post_urls:
driver.get(post_url)
time.sleep(4)
# Try to expand hidden replies if available
try:
expand_buttons = driver.find_elements(By.XPATH, "//button[contains(text(),'View')]")
for btn in expand_buttons:
btn.click()
time.sleep(1)
except:
pass
# Grab all visible comment blocks
comments = driver.find_elements(By.CSS_SELECTOR, "div[role='article']")
for comment in comments:
try:
user_elem = comment.find_element(By.CSS_SELECTOR, "a[href*='/@']")
username = user_elem.text.strip('@')
if username == target_username:
# Use innerHTML fragment to hash comment ID
comment_id = comment.get_attribute("innerHTML")[:100]
if comment_id in replied_to:
continue # already replied
# Extract and print comment content
comment_text_elem = comment.find_element(By.CSS_SELECTOR, "div[dir='auto']")
comment_text = comment_text_elem.text.strip()
print(f"π¬ @{target_username} said: \"{comment_text}\"")
# Reply with emoji
reply_button = comment.find_element(By.XPATH, ".//button[contains(text(),'Reply')]")
reply_button.click()
time.sleep(1)
reply_box = driver.find_element(By.TAG_NAME, "textarea")
reply_box.send_keys(auto_reply)
time.sleep(1)
post_button = driver.find_element(By.XPATH, "//button[contains(text(),'Post')]")
post_button.click()
print(f"β
Replied to @{target_username} with π€‘")
replied_to.add(comment_id)
time.sleep(2)
except Exception as e:
print(f"β οΈ Skipping one comment due to error: {e}")
continue
print("π Sleeping 60 seconds before checking again...\n")
time.sleep(60)
except KeyboardInterrupt:
print("π Script interrupted by user. Exiting.")
break
except Exception as e:
print(f"π¨ Error during loop: {e}")
time.sleep(60)