[英]In Telethon: How can I verify If ChatAction was only from my group/channel, when I am not sure If my group/channel is private or public?
[英]How can I handle migration from group to supergroup in telethon?
我在#telethon 電報群中問了這個問題,但沒有得到足夠的答案。 所以,我得到了支持遷移的“代碼”:
@client.on(events.Raw(types.UpdateNewChannelMessage))
async def migrate_event(event: types.UpdateNewChannelMessage):
if event.message:
if isinstance(event.message.action, types.MessageActionChannelMigrateFrom):
was_chat_id = -1 * event.message.action.chat_id
new_id = int('-100' + str(event.message.to_id.channel_id))
raise events.StopPropagation
但是當我更改組權限或某些用戶的權限時它不起作用(例如將其轉移到管理員權限)。 我只是得到類似的東西:
UpdateChatParticipants(participants=ChatParticipants(chat_id=496384744, participants=[ChatParticipant(user_id=849120097, inviter_id=382775249, date=datetime.datetime(2020, 8, 18, 8, 28, 30, tzinfo=datetime.timezone.utc)), ChatParticipant(user_id=1038400746, inviter_id=382775249, date=datetime.datetime(2020, 8, 18, 8, 28, 30, tzinfo=datetime.timezone.utc)), ChatParticipantCreator(user_id=382775249)], version=1))
收聽原始事件時:
@client.on(events.Raw)
async def migrate_event(event):
print(event)
print(event.message.action)
我只是完全不明白,雖然這是因為較舊的 Telethon 版本(1.12),因為較新的 Telethon 版本正在發生層更改(因此其他定義在安裝時 setup.py 中內置)但我認為這是不同的問題。 我可能不知道如何正確編碼,我錯過了一些知識。
那么,知道如何正確處理它嗎?
建議的代碼正在運行,您只需要對這些值做一些事情......
from telethon import TelegramClient, events, types
...
@client.on(events.Raw(types.UpdateNewChannelMessage))
async def migrate_event(event: types.UpdateNewChannelMessage):
"""
event new incoming message, filtered by MessageActionChannelMigrateFrom
:param param1: event is the message object, types type of action
"""
if event.message:
if event.message.action is not None:
print('=========== Chat Action ===============')
if isinstance(event.message.action, types.MessageActionChannelMigrateFrom):
was_chat_id = -1 * event.message.action.chat_id
new_id = int('-100' + str(event.message.to_id.channel_id))
print('############ CHAT MIGRATION ############')
print('From_id: ' + str(was_chat_id) + 'To_id: ' + str(new_id))
這應該在每個聊天事件上打印一條消息並檢測遷移到超級組等並打印舊 ID 和新 ID。
要獲得其他操作,您還必須過濾和處理它們......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.