A
A
Andrey Begin2021-08-19 17:41:40
Python
Andrey Begin, 2021-08-19 17:41:40

How to call a command through a button in a Telegram bot?

Hi everyone, I'm using aigram.
How can I call the /help command after clicking on a button?
Is it possible to hang a handler?

I have this code that fires after the /start button is pressed:

keyboard = types.ReplyKeyboardMarkup()
                button = types.KeyboardButton(text="Статистика оценок")
                keyboard.add(button)


But after triggering, only the name of the button "Statistics of grades" is displayed in the chat. I would like to have something like this: the name of the button remains the same, but after clicking, the /help command itself went into the chat. Is it possible? Or will you have to hang a handler on the text itself, and call a further function (which will also have to be registered for the /help command)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-08-19
@MoVVe

Regular ReplyKeyboard buttons do not support this kind of loading.
Two options:
1. Hang the handler on the text "Statistics of grades"
2. Use InlineMarkup, you can already transfer payload there, while leaving your text, but it's not clear why.
Just click on the "Statistics of Grades" button so that it sends the text "/help" to the chat - you can't
Just hang two handlers

@dp.message_handler(commands=['help'])
@dp.message_handler(lambda message: message.text and 'статистика оценок' in message.text.lower())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question