B
B
Bl4ckm45k2020-12-20 23:03:23
Python
Bl4ckm45k, 2020-12-20 23:03:23

How to properly add the function of sending a message to the user?

Hello, I use the telebot library, there are several message handlers and callback query handlers, a separate function for sending a message to the user if he is in the bot database.

When importing another file, in which there is only one function (the function in the loop through twisted), the bot does not respond to messages (Most likely due to the function loop). What is the right way to call the function of sending a message to the user from the main file from this function and not interrupt the work of the handlers?

So far, I have only reached multiprocessing, but somehow I crookedly twist everything into classes and in the end nothing works.

Short example:

spoiler
import mysql.connector
import telebot
import urllib3
@bot.message_handler(commands=['start'])
def send_welcome(message):
    bot.send_message(message.chat.id,
                     "Привет.")


def send_to_user(abcp_id, number, comment, id_from): # вызывается из отдельного файла
    number_html = f'<a href="https://{domain}{method}={number}">{number}</a>'
    text_to_user = number_html  + comment
    sql_check = f"SELECT * FROM to_notify WHERE number ='{number}'"
    ex_check = cursor.execute(sql_check)
    print(cursor.execute(sql_check))
    print(type(ex_check))
    result_check = cursor.fetchall()
    print(result_check)
    sql = f"SELECT * FROM staff WHERE id ='{_id}'"
    cursor.execute(sql)
    my_result = cursor.fetchall()

if __name__ == '__main__':  ...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question