Advertisement
icarussiano

telethon

Apr 3rd, 2024
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. import os
  2. from dotenv import load_dotenv
  3. from telethon import TelegramClient, events, Button
  4.  
  5.  
  6. load_dotenv()
  7. TOKEN = os.getenv('TOKEN')
  8. API_ID = int(os.getenv('API_ID'))
  9. API_HASH = os.getenv('API_HASH')
  10. print(TOKEN, API_ID, API_HASH)
  11.  
  12. bot = TelegramClient('bot', API_ID, API_HASH).start(bot_token=TOKEN)
  13.  
  14. @bot.on(events.InlineQuery())
  15. async def inline_query(event):
  16.     builder = event.builder
  17.     empty_image="https://upload.wikimedia.org/wikipedia/commons/5/59/Empty.png"
  18.     results = [
  19.         builder.photo(
  20.             empty_image,
  21.             text="Immagine senza immagine",
  22.             buttons=Button.inline("Immagine", b"1"),
  23.             include_media=False
  24.         )
  25.     ]
  26.     await event.answer(results)
  27.  
  28. @bot.on(events.CallbackQuery())
  29. async def button(event):
  30.     if event.data == b"1":
  31.         img="https://upload.wikimedia.org/wikipedia/commons/e/e9/Felis_silvestris_silvestris_small_gradual_decrease_of_quality.png"
  32.         await event.edit_message(media=img)
  33.  
  34. with bot:
  35.     bot.run_until_disconnected()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement