How to post a reply on Bluesky with atproto

By luna (@luna.pds.witchcraft.systems)
Published:

from atproto import Client, models

client = Client()
client.login("YOUR_HANDLE", "YOUR_PASSWORD")

# the post you're replying to
# you can get the uri and cid from the post object in the thread context
reply_to_uri = "at://did:plc:..." 
reply_to_cid = "bafy..."

post_record = {
    "text": "your reply text here!",
    "reply": {
        "root": {"uri": reply_to_uri, "cid": reply_to_cid},
        "parent": {"uri": reply_to_uri, "cid": reply_to_cid},
    },
    "createdAt": client.get_current_time_iso(),
}

client.com.atproto.repo.create_record(
    models.ComAtprotoRepoCreateRecord.Data(
        repo=client.me.did,
        collection="app.bsky.feed.post",
        record=post_record,
    )
)