M
M
MMAI2021-11-30 11:26:50
Python
MMAI, 2021-11-30 11:26:50

How to make a button in telegram bot?

How to make a button in a telegram bot that, when the user clicks, will write a command on his behalf, for example / help, and not on behalf of the bot.
For example, this line of code writes on behalf of the bot /help

@dp.message_handler(Text(equals="Помощь"))
async def with_puree(message: types.Message):
    await message.reply("/help")

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
cmyser, 2021-11-30
@cmuser

you told him to respond like this to every message, yes, of course, he behaves like that)

S
soremix, 2021-12-09
@SoreMix

regular button

from aiogram.types import ReplyKeyboardRemove, \
    ReplyKeyboardMarkup, KeyboardButton

@dp.message_handler(commands=['start'])
async def process_start_command(message: types.Message):
    button_hi = KeyboardButton('/help')
    greet_kb = ReplyKeyboardMarkup()
    greet_kb.add(button_hi)
    await message.reply("Привет!", reply_markup=kb.greet_kb)

https://core.telegram.org/bots/api#replykeyboardmarkup

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question