Answer the question
In order to leave comments, you need to log in
How to add number to number from sqlite db?
I have a table in db where a number is located. How to change this field? For example, the bot rolls a die, 5 falls out and you need to add this 5 to the number from the database.
@dp.message_handler(commands=['dice'])
async def dice_handler(message: types.Message):
user_data = await message.answer_dice(emoji="")
user_data = user_data['dice']['value']
conn = sqlite3.connect('db.db')
cur = conn.cursor()
user_id = message.from_user.id
result = cur.execute("SELECT * FROM users WHERE user_id = ?", (user_id, )).fetchone()
nomer = result[5] # это расположение числа с которым нужно работать
if user_data == 1:
await sleep(4)
await message.reply("Число 1")
nomer + 1 # это моя жалкая попытка изменить число
elif user_data == 2:
await sleep(4)
await message.reply("Число 2")
nomer + 2
elif user_data == 3:
await sleep(4)
await message.reply("Число 3")
nomer + 3
elif user_data == 4:
await sleep(4)
await message.reply("Число 4")
nomer + 4
elif user_data == 5:
await sleep(4)
await message.reply("Число 5")
nomer + 5
elif user_data == 6:
await sleep(4)
await message.reply("Число 6")
nomer + 6
Answer the question
In order to leave comments, you need to log in
number = # на сколько нужно увеличить то число
cur.execute("UPDATE users SET number = number + ? WHERE user_id = ?", (number, user_id))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question