Search code examples
python-3.xpython-telegram-bot

Python-telegram-bot know which button without changing keyboard


I have an InlineKeyboard which shows me a list of possible numbers that an user can choose to then bet on those numbers to roll a dice, I want to know if the user clicked two buttons so that he can bet on two numbers at the same time e.g. the user selects the 1 and 4 and then roll the dice.

query.data == "demo":
    keyboard_demo = [
       [
        InlineKeyboardButton("1", callback_data="Dice1"),
        InlineKeyboardButton("2", callback_data="Dice2"),
        InlineKeyboardButton("3", callback_data="Dice3"),
        InlineKeyboardButton("4", callback_data="Dice4"),
        InlineKeyboardButton("5", callback_data="Dice5"),
        InlineKeyboardButton("6", callback_data="Dice6"),
    ],
    [
        InlineKeyboardButton("Even", callback_data="DiceEven"),
        InlineKeyboardButton("Odd", callback_data="DiceOdd"),
    ],
    [
        InlineKeyboardButton("Back", callback_data="DiceBack"),
    ],
    [
        InlineKeyboardButton("Roll", callback_data="DiceRoll"),
    ],
    ]

I then want to store the numbers or the options that the user chose to then determine if He won or not.

I was thinking of using a list to store all the possible outcomes that the user chose but I dont know how to populate the list without changing keyboard everytime with every button push


Solution

  • I believe you want to store context and then process. I would suggest you look into the following documentation:

    https://github.com/python-telegram-bot/python-telegram-bot/wiki/Storing-bot%2C-user-and-chat-related-data

    and the below example

    https://docs.python-telegram-bot.org/en/v20.6/examples.conversationbot2.html