M
M
Misha Utka2021-05-26 16:00:29
JavaScript
Misha Utka, 2021-05-26 16:00:29

The bot crashes when writing a command, what should I do?

I have this handler in my bot

@bot.message_handler(regexp=r"/\w\d+")
def about_me(message):
  user_type = message.text[1:2]
  user_id = int(message.text[2:])

It accepts commands like /c1, /e47, /f128, but when you enter a command that does not exist /c1\ or for example /c53e, /c12gdf, an error occurs in the console and the bot turns off, how to make it not stop working

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alexandrryabchuk, 2019-01-07
@alexandrryabchuk

return ['price'=>100, 'number'=10, 'photo'=>'photo.jpg']

I
Ilya, 2019-01-07
@jasper-blondin

Already during this time they would have found a freelance student who wrote all the code for whitewash. Instead of spawning topics on the toaster))

S
soremix, 2021-05-26
@ut1ka

The easiest way is to modify the decorator by adding ^ and $ to delimit the string
@bot.message_handler(regexp=r"^/\w\d+$")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question