Answer the question
In order to leave comments, you need to log in
How to get and send all the strings in the Telegram bot that include one of the variables in the database?
I need to extract the name from a string, for example: "s Miha", and use it to find all the lines in the database where this name is, and accordingly send it all in a message to the user.
I tried to write this code:
@bot.message_handler(func=lambda m: True)
def show_oper(message):
if message.text.startswith("s"):
mess_oper_name = message.text.split()[1]
with sqlite3.connect('database.db') as db:
cursor = db.cursor()
result = cursor.execute('SELECT * FROM opers_list WHERE oper = ?', [mess_oper_name]).fetchall()
bot.reply_to(message, '\n'.join(result))
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