G
G
ganyamede2021-08-03 23:23:45
Python
ganyamede, 2021-08-03 23:23:45

What is wrong with sqlite telebot?

import telebot
import sqlite3
from telebot import types
bot = telebot.TeleBot('1714393749:AAHJaKm0Ts_nIZMNJq5vXRjc-vQBM6dNUNU')




@bot.message_handler(commands=['ps'])
def star(message):
    connect = sqlite3.connect('sssa.db')
    cursor = connect.cursor()
    cursor.execute("""CREATE TABLE IF NOT EXISTS login_id(
        id INTEGER
    )""")
    connect.commit()
    people = message.chat.id
    cursor.execute(f"SELECT id FROM login_id WHERE id = {people}")
    data = cursor.fetchone()
    if data is None:
        user_id = [message.chat.id]
        cursor.execute("INSERT INTO login_id VALUES(?);", user_id)
        connect.commit()
    else:
        bot.send_message(message.chat.id, 'di nax')
        
@bot.message_handler(commands=['start'])
def start(message):
    if message.chat.id in data:
        bot.send_message(message.chat.id, 'Команды доступные')
    if not message.chat.id in data:
        bot.send_message(message.chat.id, 'Команды не доступны, введите /ps что бы\nНачать пользоваться командами!')



@bot.message_handler(commands=['sp'])
def sta(message):
    connect = sqlite3.connect('sssa.db')
    cursor = connect.cursor()
    people = message.chat.id
    cursor.execute(f"DELETE FROM login_id WHERE id = {people}")
    connect.commit()



if __name__ == '__main__':
  bot.polling(none_stop=True)

И вот ошибка:

 File "/home/effffffwgve/.pythonstartup.py", line 29, in start
    if message.chat.id in data:
NameError: name 'data' is not defined

Должно получиться, что чел после того как ввел команду мог писать иные команды которые я напишу после того как я узнаю как решить ошибку, буду благодарен кто поможет!!!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
HemulGM, 2021-08-04
@ganyamede

@bot.message_handler(commands=['start'])
def start(message):
    if message.chat.id in data:
        bot.send_message(message.chat.id, 'Команды доступные')

Where did you get your data from? Is it really hard to understand the error? It's written in Russian there.

S
Sergo Zar, 2021-08-04
@Sergomen

You don't have data variable declared

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question