How to get telegram's channel description in Telethon?
Asked Answered
H

3

6

I'm writing a client of telegram using Telethon. How can i get channel description? get_entity method does not provide channel description.

Holystone answered 24/1, 2018 at 21:54 Comment(0)
B
8

There is GetFullChannelRequest method

from telethon.tl.functions.channels import GetFullChannelRequest
# creating client here
ch = client.get_entity("@mychannel")
ch_full = client(GetFullChannelRequest(channel=ch))
ch_full.full_chat.about # this is what you need

So you may want to inspect full_chat attribute as it includes rest of info

Bodkin answered 28/3, 2018 at 11:36 Comment(1)
I would just recommend using get_input_entity() to reduce network requests by using caching.Glovsky
F
1

Another example of usage with a bot

from telethon.sync import TelegramClient, events
from telethon import functions

bot = TelegramClient(
    'bot', API_ID, API_HASH).start(bot_token=BOT_TOKEN)

@bot.on(events.NewMessage)
async def my_event_handler(event):
    chat = await event.get_chat()
    result = await bot(functions.messages.GetFullChatRequest(
        chat_id=chat.id
    ))
    print(result.full_chat.about)

bot.run_until_disconnected()
Fritz answered 23/12, 2019 at 10:10 Comment(0)
R
0

You have to use getChat method with chat_id or @username, and .result.description is what you need.

Riannon answered 25/1, 2018 at 0:7 Comment(2)
Could you add some lines of code. Is getChat method of Channel class?Holystone
In fact, I didn't know how to use it in Python, it is Bot API method :(Riannon

© 2022 - 2024 — McMap. All rights reserved.