'How to get the user_money value from the database so that it is output with the /money command?
How do I get the user_money value from the SQLite database and output it with the /money command? it is necessary that when entering the /money command, the value from the sqlite database is output. How to implement it? I write in python, pyTelegramBotAPI.
import telebot
import sqlite3
bot = telebot.TeleBot('5107117113:AAFKBPtDjw_ZCNn7agSUhIfHSXal5vN_dds')
@bot.message_handler(commands=['start'])
def start(message):
connect = sqlite3.connect('users.db')
cursor = connect.cursor()
cursor.execute("""CREATE TABLE IF NOT EXISTS login_id(
id INTEGER, money INTEGER
)""")
connect.commit()
people_id = message.chat.id
cursor.execute(f"SELECT id FROM login_id WHERE id = {people_id}")
data = cursor.fetchone()
if data is None:
user_id = message.chat.id
user_money = '10000'
cursor.execute("INSERT INTO login_id VALUES(?, ?);", (user_id, user_money))
connect.commit()
bot.send_message(message.chat.id, 'Вы успешно зарегестрирован. Ваш баланс: 10000 рублей.')
else:
bot.send_message(message.chat.id, 'Вы уже в базе')
@bot.message_handler(commands=['money'])
def money(message):
connect = sqlite3.connect('users.db')
cursor = connect.cursor()
user_money = cursor.fetchall()
people_id = message.chat.id
cursor.execute(f"SELECT user_money FROM login_id WHERE id = {people_id}")
bot.send_message(message.chat.id, 'Ваше бабло:', user_money)
bot.polling()
```[enter image description here][1]
[1]: https://i.stack.imgur.com/esVHk.jpg
Solution 1:[1]
bot.send_message(message.chat.id, '???? ?????:', {user_money})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ÐÐ’ÐÐ’ÐÐ’Ð Ð’ÐОÐВОÐВО |
