@client.on(events.NewMessage(chats=channel_username))
async def handle_new_post(event):
last_post = event.message
await last_post.reply(comment_message)
with client:
client.run_until_disconnected()
async def comment_last_post(client, message):
channel_username = "chenal_name"
messages = await client.get_chat_history(channel_username, limit=1)
if messages:
comment_text = "комментарий"
await client.send_message(channel_username, text=comment_text, reply_to_message_id=messages[0].message_id)
comment_last_post():
channel = await find_channel(channel_username)
if channel:
async for message in client.iter_messages(channel, limit=1):
if message:
await client(SendMessageRequest(
peer=InputPeerChannel(channel_id=channel.id, access_hash=channel.access_hash),
message=message_text
))