X
X
XWR2021-06-23 20:51:03
Python
XWR, 2021-06-23 20:51:03

How to modify the code of a telegram bot written in aiogram?

Guys, please help to finalize the code.
If a person writes /random a1936, for example,
then there will be an error in the console, but how to make the bot send the user to write only numbers

Here is the code:

@dp.message_handler(commands=['random'])
async def rang(message: types.Message):
    random6 = int(message.text.split()[1])
    if random6 <= 10:
        random_number = random.randint(0, random6)
        await message.answer(f' Выпало случайное число из [0, {random6}] выпало на число {random_number}')
    elif random6 >= 10:
        await message.answer(f' Введите число меньше 10')
    else:
        await message.answer(f' ошибка')

Tell me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-06-23
@XWR

do a random6.isdigit() check

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question