N
N
nikolays1005002021-11-15 11:45:00
Python
nikolays100500, 2021-11-15 11:45:00

How to make telegram bot send private messages?

Tell me how to write lines of code so that, by the id of my telegram, the telegram bot sends a message about a new user who used my bot? All users are added to the db file.

### menu ###
@dp.message_handler(commands=['start'])
async def send_welcome(message: types.Message):
    user_id = message.chat.id
    splited = message.text.split()
    if not Users.user_exists(user_id):
        Users.create_user(user_id)
        if len(splited) == 2:
            Users.increase_ref_count(splited[1])
    await bot.send_message(message.chat.id,text = f' Привет,<b>‍‍‍{message.from_user.first_name}‍‍‍</b>\nВаш <b> {message.from_user.id}</b>\n<b>Для использования бота используйте кнопки ниже</b>',parse_mode = 'HTML',reply_markup = kb.home)
    print(f'Новый юзер - {message.from_user.first_name}')
    cursor.execute("select * from users where user = ?",(message.from_user.id,))
    usr = cursor.fetchone()
    if not usr:
        cursor.execute("INSERT INTO users values (:user, :name, :allorders, :balance, :allmoney, :orders);" ,
        {'user':message.from_user.id,
        'name':message.from_user.first_name,
        'allorders':orderr,
        'balance':bal,
        'allmoney':allm,
        'orders': ""})
        conn.commit()

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