D
D
DaniilSh2021-02-13 13:17:03
Bots
DaniilSh, 2021-02-13 13:17:03

How to check message for type int?

The telegram bot should write the user's message to a variable. How to reject values ​​that are not in the int type and tell the user that he must enter exactly a number?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeniy, 2021-02-13
@DaniilSh

To begin with, you find out what type the message has, then you compare ==, if false, reject if true, accept.

M
Muv3k, 2021-02-14
@Muv3k

Use a custom function

def is_number(number):
    try:
        int(number)
        return True
    except ValueError as ex:
        return False

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question