我有这个代码
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")
如何实现?
答案 0 :(得分:2)
如果我们仅谈论组/渠道
chat_from = event.chat if event.chat else (await event.get_chat()) # telegram MAY not send the chat enity
chat_title = chat_from.title
其他(如果我们想获取聊天实体的全名,包括用户):
from telethon import utils
hat_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)
get_display_name()实际上获得您将看到的名称。适用于类型User, Channel, Chat
该方法不得具有await