sergey91sergeev

Untitled

Oct 12th, 2024
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import asyncio
  2. from aiogram import Bot, Dispatcher, types
  3. from aiogram import executor
  4. """example_bot"""
  5.  
  6. API_TOKEN = "7286581991:AAFGS0iOufIK4-NSQs2HXIgRV8r2hiyRzTY"
  7. bot = Bot(token=API_TOKEN)
  8. dp = Dispatcher(bot)
  9. """Урок с кнопками Inline"""
  10.  
  11. @dp.message_handler(commands=["start"])
  12. async def start_handler(message: types.Message):
  13.     keyboard = types.InlineKeyboardMarkup(row_width=2)
  14.     button_photo1 = types.InlineKeyboardButton("фото1", callback_data="photo1")
  15.     button_photo2 = types.InlineKeyboardButton("фото2", callback_data="photo2")
  16.     keyboard.add(button_photo1, button_photo2)
  17.     await bot.send_message(message.chat.id,"Привет!", reply_markup=keyboard)
  18.  
  19.  
  20. @dp.message_handler(commands=["help"])
  21. async def help_handler(message: types.Message):
  22.     await message.reply("Помощь!")
  23.     print(message)
  24.  
  25.  
  26. @dp.callback_query_handler(text="photo1")
  27. async def photo_handler(callback: types.CallbackQuery):
  28.     await bot.send_photo(callback.from_user.id, photo="https://static.wikia.nocookie.net/heartforest/images/d/d5/S1200_%285%29.jpg/revision/latest?cb=20191028134430&path-prefix=ru")
  29.     print(callback)
  30.  
  31. if __name__ == "__main__":
  32.     executor.start_polling(dp, skip_updates=True)
Tags: bot
Advertisement
Add Comment
Please, Sign In to add comment