[英]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.