N
N
Nikolai Neizvestny2020-04-27 03:00:41
Python
Nikolai Neizvestny, 2020-04-27 03:00:41

Delete user from database if 403 bot was blocked by the user?

How to delete the person from the database if the user deleted the bot and the error
403 bot was blocked by the user during mailing?

def start(bot, update):
    message = update.message
    base_work.user_init(message.chat.id, message.chat.username, message.chat.first_name)

What exactly should I put in try/except?
Sorry I'm just learning

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-04-27
@shabelski89

def post_sql_query(sql_query):
    with sqlite3.connect(database) as connection:
        cursor = connection.cursor()
        try:
            cursor.execute(sql_query)
        except Error:
            print(Error)
        result = cursor.fetchall()
        return result

def delete_user(user_id):
    del_user_query = f'DELETE FROM users WHERE user_id = {user_id};'
    post_sql_query(del_user_query)

try:
    bot.send_message(user_id, text)
except telebot.apihelper.ApiException:
    delete_user(user_id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question