How do I create sticker packs and add stickers to them using Pyrogram raw functions and my Telegram bot? I attempted to use Pyrogram.raw functions, but encountered errors. I've consulted the documentation, reviewed examples, and searched Pyrogram's official group, but haven't found a solution. Any guidance would be appreciated.
I've found a solution that I hope it to be useful for you too. here is the custom function I've written
def create_or_add_sticker(user_id, document, emojis, title, short_name) -> raw.base.messages.StickerSet:
media = (bot.invoke(UploadMedia(
peer=bot.resolve_peer('stickers'),
media=InputMediaUploadedDocument(
mime_type="image/png",
file=(bot.save_file(document)),
force_file=True,
thumb=None,
attributes=[DocumentAttributeFilename(file_name=document)])))
).document
sticker = InputStickerSetItem(document=InputDocument(id=media.id, access_hash=media.access_hash, file_reference=media.file_reference), emoji=emojis)
try:
result = bot.invoke(CreateStickerSet(user_id=InputUser(user_id=user_id, access_hash=bot.resolve_peer(user_id).access_hash), title=title, short_name=short_name, stickers=[sticker]))
except:
stickerset: raw.base.messages.StickerSet = bot.invoke(GetStickerSet(stickerset=InputStickerSetShortName(short_name=short_name), hash=0))
if stickerset.set.count == 120:
stdt = stickerset.documents[-2]
bot.invoke(
RemoveStickerFromSet(sticker=InputDocument(id=stdt.id, access_hash=stdt.access_hash, file_reference=stdt.file_reference))
)
result = bot.invoke(AddStickerToSet(stickerset=InputStickerSetShortName(short_name=short_name), sticker=sticker))
return result