Answer the question
In order to leave comments, you need to log in
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)
Welcome your balance is Falsealthough in the database this cell is set to 50 (if you remove if and write fetchall(), then the output is just [] )
Answer the question
In order to leave comments, you need to log in
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!
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 questionAsk a Question
731 491 924 answers to any question