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) 


森栏
浏览 100回答 1
1回答

慕斯王

我想通了伙计们:# 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):&nbsp; &nbsp; # extracts the hash of that link&nbsp; &nbsp; hash = re.search('(?<=joinchat\/)(\w+[-]?\S\w+)', event.raw_text).group(0)&nbsp; &nbsp; checked = await client(CheckChatInviteRequest(hash=hash))&nbsp; &nbsp; if checked.megagroup and checked.broadcast == False:&nbsp; &nbsp; &nbsp; &nbsp; updates = await client(ImportChatInviteRequest(hash))client.start()client.run_until_disconnected()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python