skip to Main Content

I use pyrogram for my bot

I want to send a messages with buttons:

from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton,ReplyKeyboardMarkup
from pyrogram import types

def cmd_start(self, chat_id, message):
    with Client("my_acc", api_id=self.api_id,api_hash=self.api_hash,proxy=self.proxy) as app:
            
        start_service = types.InlineKeyboardButton(text='but1', callback_data='service')
        start_system = types.InlineKeyboardButton(text='but2', callback_data='system')
        start_check = types.InlineKeyboardButton(text='but3', callback_data='check')
        start_other = types.InlineKeyboardButton(text='but4', callback_data='other')
        start_keyboard = types.ReplyKeyboardMarkup(keyboard=[[start_service, start_system], [start_check, start_other]])
        
        app.send_message(chat_id, 'test', reply_markup=start_keyboard)

The sending is successfull, but I see only simple text message ‘test’ in the chat instead of 4 buttons

2

Answers


  1. Don’t use ReplyKeyboardMarkup for inline keyboards – use InlineKeyboardMarkup instead.

    Do something like this:

    start_service = types.InlineKeyboardButton(text='but1', callback_data='service')
    start_system = types.InlineKeyboardButton(text='but2', callback_data='system')
    start_check = types.InlineKeyboardButton(text='but3', callback_data='check')
    start_other = types.InlineKeyboardButton(text='but4', callback_data='other')
    
    start_keyboard = types.InlineKeyboardMarkup(inline_keyboard=[[start_service, start_system], [start_check, start_other]])
            
    app.send_message(chat_id, 'test', reply_markup=start_keyboard)
    
    Login or Signup to reply.
  2. inline keyboard can be send only by a Bot! you should set bot_token=<token> in kwargs of Client

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search