Answer the question
In order to leave comments, you need to log in
How to get last pinned message in Telegram channel in Python?
Hello everyone, I would like to get a pinned message from a telegram channel using events, here is my code.
from telethon import TelegramClient, events, utils
import server
async def handler_all(event):
pinned_message = ''
server.post(pinned_message)
Answer the question
In order to leave comments, you need to log in
from telethon import TelegramClient, events, utils
import server
async def handler_all(event):
if event.action_message == None and event.new_pin == True:
return
channel_id = event.action_message.peer_id.channel_id
message_id = event.action_message.reply_to.reply_to_msg_id
print(message_id)
messages = await client.get_messages(channel_id, limit=100)
for message in messages:
if message.id == message_id:
print("[+] Найдено новое закрепленное сообщение")
server.post(message.text)
break
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question