skip to Main Content

Is there any method to send stickers using the id attribute of event.file? The documentation points out to send it using the id and the access_hash of a particular sticker set and then finally using index with sticker_set to send the sticker. Since there’s unique id for particular sticker stored in telegram servers, I was wondering if there’s any method of using that to send stickers?

2

Answers


  1. from telethon.tl.functions.messages import GetAllStickersRequest
    sticker_sets = await client(GetAllStickersRequest(0))
    
    # Choose a sticker set
    from telethon.tl.functions.messages import GetStickerSetRequest
    from telethon.tl.types import InputStickerSetID
    sticker_set = sticker_sets.sets[0]
    
    # Get the stickers for this sticker set
    stickers = await client(GetStickerSetRequest(
        stickerset=InputStickerSetID(
            id=sticker_set.id, access_hash=sticker_set.access_hash
        )
    ))
    
    # Stickers are nothing more than files, so send that
    await client.send_file('me', stickers.documents[0])
    
    Login or Signup to reply.
  2. You must send the sticker as an InputDocument, specifying the sticker id, access_hash and file_reference.

    from telethon import types
    
    # some code here
    await event.reply(
        file = types.InputDocument(
           id = YOUR_STICKER_ID,
           access_hash = YOUR_STICKER_ACCESS_HASH,
           file_reference = YOUR_STICKER_FILE_REFERENCE
         )
    )
    # more code
    

    For example, reply to "/sticker" new message:

    from telethon import events, types
    
    # Reply to new message /sticker
    @client.on(events.NewMessage(pattern=r'/sticker'))
       await event.reply(
           file = types.InputDocument(
              id = YOUR_STICKER_ID,
              access_hash = YOUR_STICKER_ACCESS_HASH,
              file_reference = YOUR_STICKER_FILE_REFERENCE
           )    
        )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search