Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
437 views
Welcome To Ask or Share your Answers For Others

1 Answer

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...