How to find the sticker set through a sticker belongs to that sticker set?

Viewed 372

I'm learning telethon. I can download a sticker from message.

async for message in client.iter_messages(group_name):
      if message.sticker:
         path = await message.download_media()

But I don't know how to get its entire sticker set. The type of sticker I get from message is Document. How can I get the access_hash and id of its sticker set so that I can use the following code.

stickers = await client(GetStickerSetRequest(
    stickerset=InputStickerSetID(
        id=sticker_message.id, access_hash=sticker_message.access_hash
    )
))
1 Answers

As you correctly identified, stickers are Document. What sets them apart from other documents is their DocumentAttributeSticker, which has a stickerset of type InputStickerSet and can be used in the GetStickerSetRequest method:

from telethon import types

...

if message.sticker:
    for attr in message.sticker.attributes:
        if isinstance(attr, types.DocumentAttributeSticker):
            pack = await client(GetStickerSetRequest(attr.stickerset))
            # use pack
Related