Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python telethon中的事件实体_Python_Entities_Telethon - Fatal编程技术网

Python telethon中的事件实体

Python telethon中的事件实体,python,entities,telethon,Python,Entities,Telethon,当表情符号出现在文本中时,我对实体有问题 这是我的文字: ❓async def handler(event): content = event.raw_text for ent, txt in event.get_entities_text(): # ent : shows you the MessageEntity constructor # txt : shows you the text interested if isin

当表情符号出现在文本中时,我对实体有问题

这是我的文字:

async def handler(event): 
    content = event.raw_text
    for ent, txt in event.get_entities_text():
        # ent : shows you the MessageEntity constructor
        # txt : shows you the text interested
        if isinstance(ent, types.MessageEntityMention): # check if it's a mention
            content = content.replace(txt, '@example')

有关
get\u entities\u text

的更多信息,请查看,偏移量是在带有代理项的文本中计算的,因此您需要在使用以下项执行操作之前添加它们:

来自telethon导入帮助程序
text=helpers.add_代理(message.raw_text)
... # 使用“text”和“message.entities”(偏移量现在就可以了)
text=helpers.del_代理项(text)#完成后删除代理项对
答案中的kill所展示的方法更适合于你的情况,但这就是在你需要的情况下它的工作原理