Answer the question
In order to leave comments, you need to log in
How to extract and add a string with variables from SQLite3 to a Telegram bot message (Telebot)?
Hello! Please help, I will be extremely grateful. I need to add 2 variables and one row from SQLite3. How should this happen when sending opr. messages from the user, the bot must pull out the string "value", add it to the variable b and add it to the randomizer (also a variable), and send it to the user. After that, the final result (vd) should be updated in the value line. Below is the whole code:
import telebot # Библиотека Отвечающая За Работу Бота
import sqlite3 # Библиотека Базы Данных
import random
# import aiogram
# Переменные
a = int(random.randint(-15, 15))
b = 0
v = 0
# Апи токен бота
bot = telebot.TeleBot('5210000000:AAGiCqcLNk2MWpgWkm****************')
# Присоединение к базе данных
conn = sqlite3.connect('DicksVolues.db', check_same_thread=False)
cursor = conn.cursor()
def db_table_val(user_id: int, user_name: str, user_surname: str, username: str, value: int):
cursor.execute('INSERT INTO DicksVolue (user_id, user_name, user_surname, username, value) VALUES (?, ?, ?, ?, ?)', (user_id, user_name, user_surname, username, value))
conn.commit()
# Верификация
@bot.message_handler(commands=["start"])
def start(message):
bot.send_message(message.chat.id, text="Привеt! Пройди 2 этапа верификации.\nДля верификации нажми на /winokey")
@bot.message_handler(commands=["winokey"])
def start(message):
bot.send_message(message.chat.id, text="Остался 2-ой этап верификации.\nДля окончания верификации нажми на /opiut")
@bot.message_handler(commands=["opiut"])
def send_message(message):
bot.reply_to(message, text="Вы прошли верификацию!")
# Изменение и добавление жезла
@bot.message_handler(commands=["negr"])
def start(message):
#records = cursor.fetchmany()
#for row in records:
# vd = int(b + row[6] + a)
bot.reply_to(message, "Твой чёрный жезл стал " + vd)
us_id = message.from_user.id
us_name = message.from_user.first_name
us_surname = message.from_user.last_name
username = message.from_user.username
value = message.from_user.from_user
db_table_val(user_id=us_id, user_name=us_name, user_surname=us_surname, username=username, value=vd)
# try:
# records = cursor.fetchone()
# for row in records:
# vd == int( b + row[6] + a)
#
# except sqlite3.Error as error:
# print("Ошибка при работе с SQLite", error)
# Запуск бота на бесконечное обслуживание
bot.polling(none_stop=True)
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