Ива*_*хин 3 python telegram telethon
我有这个代码
from telethon.sync import TelegramClient, events
with TelegramClient('name', api_id, api_hash) as client:
@client.on(events.NewMessage(pattern=pattern))
async def handler(event):
await event.reply("Here should be the Chat or Group name")
Run Code Online (Sandbox Code Playgroud)
如何实施?
如果我们只讨论组/频道
chat_from = event.chat if event.chat else (await event.get_chat()) # telegram MAY not send the chat enity
chat_title = chat_from.title
Run Code Online (Sandbox Code Playgroud)
否则(如果我们想获取聊天实体的全名,包括用户):
from telethon import utils
chat_from = event.chat if event.chat else (await event.get_chat()) # telegram MAY not send the chat enity
chat_title = utils.get_display_name(chat_from)
Run Code Online (Sandbox Code Playgroud)
get_display_name() 实际上得到一个你会看到的名字。适用于User, Channel, Chat
该方法不应具有的类型await