Answer the question
In order to leave comments, you need to log in
How to repeat code from command in button click handler?
If when you click a button, you need to do the same thing as in the command. Do I need to write it again or is there something easier?
@dp.message_handler(commands=['test'])
async def test(message):
user_id = message.from_user.id
keyboard = types.InlineKeyboardMarkup()
callback_button1 = types.InlineKeyboardButton(text="повторить", callback_data="test1")
keyboard.add(callback_button1)
rrr = str(random.randint(1, 51))
await message.reply(f'Твое число{rrr}', reply_markup=keyboard)
@dp.callback_query_handler(lambda call: True)
async def callback_inline1(call):
user_id = call.from_user.id
result = cur.execute("SELECT * FROM users WHERE user_id = ?", (user_id, )).fetchone()
with suppress(MessageNotModified):
if call.message:
if call.data == "test1":
#тут я должен повторить все как в команде /test
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question