我正在使用Telethon API 想要提取我所属频道的所有频道的固定消息。 请指导我的程序。
谢谢。
答案 0 :(得分:1)
use可以使用GetFullChannelRequest
和GetHistoryRequest
方法从一个频道中提取固定消息
from telethon import TelegramClient
from telethon.tl.functions.channels import GetFullChannelRequest
from telethon.tl.functions.messages import GetHistoryRequest
from telethon.tl.types import PeerChannel
api_id = XXXXX
api_hash = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
phone_number = '+98XXXXXXXX'
################################################
client = TelegramClient('session_name',
api_id,
api_hash
)
assert client.connect()
if not client.is_user_authorized():
client.send_code_request(phone_number)
me = client.sign_in(phone_number, input('Enter code: '))
channel_entity = client.get_entity(PeerChannel(channel_id))
channel_info = client(GetFullChannelRequest(channel_entity))
pinned_msg_id = channel_info.full_chat.pinned_msg_id
if pinned_msg_id is not None:
posts = client(GetHistoryRequest(
channel_entity,
limit=1,
offset_date=None,
offset_id=pinned_msg_id + 1,
max_id=0,
min_id=0,
add_offset=0,
hash=0
))
print(posts.messages[0].to_dict())
我使用Telethon V0.19
,但之前的版本几乎相同
答案 1 :(得分:1)
从Telethon 1.2开始,代码要简单得多:
var form = FormApp.openById('1Cu14yeOAUYdCST-G8uipGOVPW4qArVcT-7_ElQpmkgE');
var allTriggers = ScriptApp.getProjectTriggers();
if(allTriggers.length<1){
ScriptApp.newTrigger('sendEmailToTutor')
.forForm(form)
.onFormSubmit()
.create();
} else if(allTriggers.length>1) {
ScriptApp.deleteTrigger(allTriggers[2]);
}