Answer the question
In order to leave comments, you need to log in
Not receiving a number after the command, should the bot send a message?
When someone writes to the bot: "/number 5" the bot replies: "Your number is 5" But if someone writes "/number" then an error pops up because there is no number. How to make the bot write in such a situation: "Enter a number"
@dp.message_handler(commands=['number'])
async def number(message: types.Message):
number = message.get_args()
number1 = int(number)*1000
if int(number) < 0:
await message.reply("Нельзя вводить отрицательное число")
else:
await message.reply(f"Твое число {number1}")
Answer the question
In order to leave comments, you need to log in
I suspect that number is set to None so that it can be tied to.
Try this, it might work
@dp.message_handler(commands=['number'])
async def number(message: types.Message):
number = message.get_args()
if number is None:
await message.reply(f"Твое число {number}")
else:
await message.reply("Введите число")
Based on your
@dp.message_handler(commands=['number'])
async def number(message: types.Message):
number = message.get_args()
number1 = int(number)*1000
if int(number) < 0:
await message.reply("Нельзя вводить отрицательное число")
else:
await message.reply(f"Твое число {number1}")
@dp.message_handler(commands=['number'])
async def number(message: types.Message):
number = message.get_args()
if number is not None and number.isdigit():
if int(number) < 0:
await message.reply("Нельзя вводить отрицательное число")
else:
await message.reply(f"Твое число {int(number) * 1000}")
elif number is None:
await message.reply(f'Введите число после команды "/number 5 "')
else:
await message.reply(f'После команды "/number" ожидается число, а не текст')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question