Home > front end >  How to trigger CallBackQueryHandler returned by the user with a regex pattern?
How to trigger CallBackQueryHandler returned by the user with a regex pattern?

Time:11-02

I am creating a bot that has dynamic buttons and want to detect if the start of the callback query is classes_ and then allow me to further parse. How would I use regex or a built in pattern function to detect the beginning of a string?

@bot.callback_query_handler(func=lambda c: c.data == f'classes_'.startswith)
def callback_is_return(call: types.CallbackQuery):
    print('Found!')

I tried using ().startswith

CodePudding user response:

Do this.

@bot.callback_query_handler(func=lambda c: c.data.startswith('classes_'))
  • Related