Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

python - Reply buttons not showing in telegram bot

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


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

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.7k users

...