Aayco

Send Gift

May 4th, 2025
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. from telethon import TelegramClient, events
  2. from telethon.tl.functions.payments import GetStarGiftsRequest, GetPaymentFormRequest, SendStarsFormRequest
  3. from telethon.tl.types import InputInvoiceStarGift
  4. api_id = 123
  5. api_hash = ''
  6. bot_token = ''
  7. admins = [7682429075]
  8. client = TelegramClient('bot_session', api_id, api_hash).start(bot_token=bot_token)
  9. @client.on(events.NewMessage(pattern=r'/send (.+) (.+)'))
  10. async def handler(event):
  11.     if event.sender_id not in admins:return
  12.     try:
  13.         num = int(event.pattern_match.group(2))
  14.         target = event.pattern_match.group(1).strip()
  15.         gifts = await client(GetStarGiftsRequest(hash=0))
  16.         gift = gifts.gifts[num]
  17.         user = await client.get_input_entity(target)
  18.         invoice = InputInvoiceStarGift(peer=user, gift_id=gift.id, include_upgrade=True if 'up' in event.message.message else False, hide_name=True)
  19.         payment_form = await client(GetPaymentFormRequest(invoice=invoice))
  20.         result = await client(SendStarsFormRequest(
  21.             form_id=payment_form.form_id,
  22.             invoice=invoice,
  23.         ))
  24.         await event.reply(f"Gift sent to {target} successfully!")
  25.     except Exception as e:
  26.         await event.reply(f"Error: {e}")
  27. client.run_until_disconnected()
Advertisement
Add Comment
Please, Sign In to add comment