Answer the question
In order to leave comments, you need to log in
Falling error 2021-02-04 19:22:03,678 (__init__.py:463 MainThread) ERROR - TeleBot: "Infinity polling exception: no such column: asdf"?
Here is the code:
import telebot
from telebot import types
import sqlite3 as sq
with sq.connect("vebinar.db") as con:
cur = con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS admin (
telegram_id INTEGER PRIMARY KEY,
message_text TEXT
)""")
# keyboards
mainKeyboard = types.InlineKeyboardMarkup()
mainKey = types.InlineKeyboardButton(text='Сделать рассылку', callback_data='sendMessage')
mainKeyboard.add(mainKey)
bot = telebot.TeleBot('мой токен')
@bot.message_handler(commands=['start'])
def startMessage(message):
with sq.connect("vebinar.db") as con:
cur = con.cursor()
try:
cur.execute(f"SELECT telegram_id FROM admin WHERE telegram_id = {message.chat.id}")
id = cur.fetchone()[0]
if id == мой телеграм айди:
bot.send_message(message.chat.id, 'Доступ открыт. ✅', reply_markup=mainKeyboard)
elif id != мой телеграм айди:
bot.send_message(message.chat.id, 'Доступ закрыт. ❌')
except:
bot.send_message(message.chat.id, 'У вас нету доступа к этому разделу. ❌')
@bot.callback_query_handler(func=lambda call:True)
def check(call):
bot.send_message(call.message.chat.id, 'Введите текст для рассылки.')
bot.register_next_step_handler(call.message, sendMessage)
def sendMessage(message):
newMessage = message.text
with sq.connect("vebinar.db") as con:
cur = con.cursor()
cur.execute(f"UPDATE admin SET message_text = {newMessage}")
bot.infinity_polling(True)
Answer the question
In order to leave comments, you need to log in
Because using string interpolation to form SQL queries is a very bad idea.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question