Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from telethon import TelegramClient, events
- from telethon.tl.functions.payments import GetStarGiftsRequest, GetPaymentFormRequest, SendStarsFormRequest
- from telethon.tl.types import InputInvoiceStarGift
- api_id = 123
- api_hash = ''
- bot_token = ''
- admins = [7682429075]
- client = TelegramClient('bot_session', api_id, api_hash).start(bot_token=bot_token)
- @client.on(events.NewMessage(pattern=r'/send (.+) (.+)'))
- async def handler(event):
- if event.sender_id not in admins:return
- try:
- num = int(event.pattern_match.group(2))
- target = event.pattern_match.group(1).strip()
- gifts = await client(GetStarGiftsRequest(hash=0))
- gift = gifts.gifts[num]
- user = await client.get_input_entity(target)
- invoice = InputInvoiceStarGift(peer=user, gift_id=gift.id, include_upgrade=True if 'up' in event.message.message else False, hide_name=True)
- payment_form = await client(GetPaymentFormRequest(invoice=invoice))
- result = await client(SendStarsFormRequest(
- form_id=payment_form.form_id,
- invoice=invoice,
- ))
- await event.reply(f"Gift sent to {target} successfully!")
- except Exception as e:
- await event.reply(f"Error: {e}")
- client.run_until_disconnected()
Advertisement
Add Comment
Please, Sign In to add comment