Telethon:我想抓取所有链接,只是加入小组,而不是渠道但是如何区分它们呢?

问题描述

这是我的代码,我需要一种获取True / False布尔值的方法,以查明所发送的链接是否为组链接

client = TelegramClient('session',api_id,api_hash)
#check whether there's a 'joinchat' in the msg text?
@client.on(events.NewMessage(outgoing=False,pattern=r'(?i).*joinchat/')) 
async def my_event_handler(event):
    #extract the hash of that link
    hash = re.search('(?<=joinchat\/)(\w+[-]?\S\w+)',event.raw_text).group(0) 

解决方法

我知道了:

# checks whether there's a 'joinchat' in the msg text?
@client.on(events.NewMessage(outgoing=False,pattern=r'(?i).*joinchat/'))
async def my_event_handler(event):
    # extracts the hash of that link
    hash = re.search('(?<=joinchat\/)(\w+[-]?\S\w+)',event.raw_text).group(0)
    checked = await client(CheckChatInviteRequest(hash=hash))
    if checked.megagroup and checked.broadcast == False:
        updates = await client(ImportChatInviteRequest(hash))

client.start()
client.run_until_disconnected()