【问题标题】:How do I prevent looping, unless I press the button, and it shows the next one and so on?如何防止循环,除非我按下按钮,它会显示下一个,依此类推?
【发布时间】:2022-01-11 10:45:45
【问题描述】:

在我按下按钮或键入之前,如何在循环中只显示一条消息,然后显示下一条消息?

picture of it now, its shows all the messages, and I want to create button which only then pressed it shows the next one

for job in jobs:
        def gen_markup():
            markup = InlineKeyboardMarkup()
            markup.row_width = 1
            markup.add(InlineKeyboardButton(text='לאתר מתגייסים', url=job[3]))
            return markup
        if int(job[6]) <= int(user.dpr) and int(job[7]) <= int(user.profil) and job[4] == user.sex or job[5] == user.sex:
            bot.send_message(message.chat.id, "<b>" + str(job[1]) + "</b>" + "\n" + str(job[2]), reply_markup = gen_markup(), parse_mode='HTML')

【问题讨论】:

    标签: python mysql loops bots telegram


    【解决方案1】:

    你可以使用这样的东西,点击按钮后它会用新的标记调用其他数据并发送消息

    @bot.callback_query_handler(func=lambda call: True)
    def callback_query(call):
        
        def gen_markup():
                markup = InlineKeyboardMarkup()
                markup.row_width = 1
                markup.add(InlineKeyboardButton(text='לאתר מתגייסים', url=job[3]))
                return markup
            
        def gen_marku1p():
                markup = InlineKeyboardMarkup()
                markup.row_width = 1
                markup.add(InlineKeyboardButton(text='לאתר מתגייסים', url=job[3]))
                return markup
            
        def gen_markup2():
                markup = InlineKeyboardMarkup()
                markup.row_width = 1
                markup.add(InlineKeyboardButton(text='לאתר מתגייסים', url=job[3]))
                return markup
            
        if call.data == "markup button text":
            bot.send_message(call.chat.id, 'text', parse_mode="html", reply_markup = gen_markup())
            
        elif call.data == "another markup button text":
            bot.send_message(call.chat.id, 'text', parse_mode="html", reply_markup = gen_markup1())
            
        elif call.data == "another markup button text":
            bot.send_message(call.chat.id, 'text', parse_mode="html", reply_markup = gen_markup2())
    

    【讨论】:

    • 我试过了,但它仍然发送了所有的消息,你能通过电报@M_A49 联系我,我会把项目发给你吗?
    • 当然,@elyxus 是我的用户名
    猜你喜欢
    • 2020-06-01
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    相关资源
    最近更新 更多