V
V
Vlad2422022-03-23 13:03:02
Python
Vlad242, 2022-03-23 13:03:02

How to delete a user from the database after he deleted the bot in telegram?

I have a telegram bot. How to remove a user from the database after he deleted the bot in telegram

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2022-03-23
@Vlad242

You can only find out what he deleted when the bot sends a message and receives an execut that he was deleted.
You need to catch the exception and call the deletion from the database.

try:
    bot.send_message(user_id, text)
except telebot.apihelper.ApiException:
    logging.exception(f'Send Notification ERROR - {telebot.apihelper.ApiException}')
    delete_user(user_id)

where the removal of the user from the database is called, where he is likely to be sent.
def delete_user(user_id):
    del_user_query = f'DELETE FROM {users_t} WHERE {users_col["user_id"]} = {user_id};'
    post_sql_query(del_user_query)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question