如何解决这个问题并实现点击内联按钮?

问题描述 投票:0回答:1

我有一个很大的用户列表,按下时会显示以下消息,然后您可以“继续”或“离开”。但这些内嵌按钮没有反应,我该怎么办?

主.py

@router_db.callback_query(lambda call: True)
async def stoptopupcall(callback: CallbackQuery):
    userinfo = cur.execute("SELECT * FROM acc WHERE callback_db = (?)", (callback.data,)).fetchone()
    if userinfo:
        await callback.message.edit_text(
                                         f"🔖 SELL {userinfo[2]} \n\n"
                                         f"👤  <b>{userinfo[1]}</b>\n\n"
                                         f"<b>rat:</b> "
                                         f"{userinfo[3]} ⭐\n<b>del:</b> "
                                         f"{userinfo[4]} | {userinfo[5]} % \n\n"
                                         f"curs {userinfo[6]}\n\n"
                                         f"buy: {userinfo[7]}\n"
                                         f"limit: {userinfo[8]}\n\n\n"
                                         f"🕑 data {nowdate}", reply_markup=kb.seller_buy_keyboard, parse_mode='HTML')


@router_db.callback_query(F.data == 'user_to_buy')
async def cb_p2p_buy(callback: CallbackQuery):
    await callback.message.answer(
        'go')

@router_db.callback_query(F.data == 'user_to_back')
async def go_to_back(callback: CallbackQuery):
    await callback.message.answer(
        'no')

kb.py

seller_buy_keyboard = InlineKeyboardMarkup(inline_keyboard=[

[

    InlineKeyboardButton(text='Continue', callback_data='user_to_buy'),
    InlineKeyboardButton(text='Back', callback_data='user_to_back'),

]
python sqlite aiogram
1个回答
0
投票

在这种情况下,您可以尝试另一种技术,即使用修改后的内联键盘标记重写消息。这是使用此方法的代码的修改版本:

# In main.py
@router_db.callback_query(lambda call: True)
async def stoptopupcall(callback: CallbackQuery):
    userinfo = cur.execute("SELECT * FROM acc WHERE callback_db = (?)", (callback.data,)).fetchone()
    if userinfo:
        message = await callback.message.edit_text(
            f"🔖 SELL {userinfo[2]} \n\n"
            f"👤  <b>{userinfo[1]}</b>\n\n"
            f"<b>rat:</b> "
            f"{userinfo[3]} ⭐\n<b>del:</b> "
            f"{userinfo[4]} | {userinfo[5]} % \n\n"
            f"curs {userinfo[6]}\n\n"
            f"buy: {userinfo[7]}\n"
            f"limit: {userinfo[8]}\n\n\n"
            f"🕑 data {nowdate}", reply_markup=kb.seller_buy_keyboard, parse_mode='HTML')

@router_db.callback_query(F.data == 'user_to_buy')
async def cb_p2p_buy(callback: CallbackQuery):
    await callback.answer('You pressed "Continue"')

@router_db.callback_query(F.data == 'user_to_back')
async def go_to_back(callback: CallbackQuery):
    await callback.answer('You pressed "Back"')

我们使用

edit_reply_markup
代替
await callback.message.edit_text
来生成具有更改后的内联键盘标记的新消息。这应该可以工作并适当地注册按钮按下。请修改代码以反映您的个人用例和 aiogram 3.0 的行为。

© www.soinside.com 2019 - 2024. All rights reserved.