Answer the question
In order to leave comments, you need to log in
Why doesn't the python bot code work?
The code does not work, there are no errors in the console, I can not understand what the error is
@dp.message_handler(regexp=r"(Купить|купить) ?(\d+)? ?(\d+)?")
async def process_start_command(message: types.Message):
balanc = cur.execute("SELECT balance from users where userid = ?", (message.from_user.id,)).fetchone()
balance = (balanc[0])
command_parse = re.compile(r"(Купить|купить) ?(\d+)? ?(\d+)?")
parsed = command_parse.match(message.text)
buy_item = parsed.group(2)
count = parsed.group(3)
if not count:
count = 1
if int(count) > 0:
if str(buy_item) == 'ручку':
final_count = count * 250000
if int(balance) >= int(final_count):
if int(count) <= 10:
data = {}
data["suma"] = int(final_count)
data['user_id'] = message.from_user.id
data1 = {}
data1["suma"] = int(count)
data1['user_id'] = message.from_user.id
cur.execute("""UPDATE users SET balance = balance - :suma WHERE userid = :user_id;""", data)
cur.execute("""UPDATE users SET pen = pen + :suma WHERE userid = :user_id;""", data1)
await message.answer( f'{name1} ты успешно купил(а) {count} за {final_count} ', parse_mode='html')
else:
await message.answer( f'{name1}, нельзя покупать более 10 едениц за 1 раз', parse_mode='html')
elif int(balance) < int(final_count):
await message.answer( f'{name1} у тебя нет столько \nТвой баланс: {balance} ', parse_mode='html')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question