Im trying to get a random number while clicking inline buttons. Im getting a message with buttons, but when i click on them nothing happends — i just see a small clock in the button. Here are my handlers:
from loader import dp
from random import randint
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from aiogram import types
button1 = InlineKeyboardButton(text="Random 1-10", callback_data="random1-10")
button2 = InlineKeyboardButton(text="Random 1-100", callback_data="random1-100")
keyboard_inline = InlineKeyboardMarkup().add(button1, button2)
@dp.message_handler(commands=["random"], state="*", content_types=types.ContentTypes.ANY)
async def cmd_random(message: types.Message):
await message.reply("Select a range", reply_markup=keyboard_inline)
@dp.callback_query_handler(text=["random1-10", "random1-100"])
async def random_value(call: types.CallbackQuery):
if call.data == "random1-10":
await call.message.answer(str(randint(1, 10)))
elif call.data == "random1-100":
await call.message.answer(str(randint(1, 100)))
await call.answer()
OR
@dp.callback_query_handler(lambda c: c.data == 'random1-10')
async def process_callback_button1(callback_query: types.CallbackQuery):
await dp.bot.answer_callback_query(callback_query.id)
await dp.bot.send_message(callback_query.from_user.id, 'First button clicked!')
I also tried to send a static message w/o any functions, but nothing happens. Maybe i need to switch on smth?