C
C
char9062021-02-05 20:15:22
Python
char906, 2021-02-05 20:15:22

Why does the telegram bot not display information from the database?

Good day. I am writing a telegram bot for an auto sales store, I need to display the user's balance from the database. SQLite database

def user_money(self, money):
        with self.connection:
            balans = self.cursor.execute('SELECT * FROM `subscriptions` WHERE `user_id` = ?',(money, )).fetchone()
            if balans is None:
                return False
            else:
                return balans

i = db.user_money(message.text)

bot.send_message(message.chat.id, 'Добро пожаловать, твой баланс '+str(i)+' {0.first_name}!\nЯ - <b>{1.first_name}</b>'.format(message.from_user, bot.get_me()),
        parse_mode='html', reply_markup=markup)


The output is always
Welcome your balance is False
although in the database this cell is set to 50 (if you remove if and write fetchall(), then the output is just [] )

As I understand the problem is that I write the SQL syntax incorrectly, there is a huge feeling that I am stupid out of the blue it's only the second day I can't figure out how to solve it

Thanks in advance for your answer!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
char906, 2021-02-05
@char906

Made a conclusion of the data from a DB.
As it turned out, it was necessary to simply change:
i = db.user_money(message.text)
to
i = db.user_money(message.from_user.id)
Thank you all for your help!

S
Sergey Karbivnichy, 2021-02-05
@hottabxp

Most likely an error in the method def user_money(self, money):
. Most likely, the user's id should be passed to the method, not money.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question