A
A
AlexaAioGram2021-07-10 14:27:40
Python
AlexaAioGram, 2021-07-10 14:27:40

How to pass a variable from one handler to another in aiogram?

@dp.message_handler(commands='start')
async def get_user_id(message: Message):
    get_all_id = execute_query(f'INSERT OR IGNORE INTO Users (User_id) VALUES ({message.from_user.id})') #Вот эта переменная 
    await message.answer(f'Привет добро пожаловать {message.from_user.first_name}')


@dp.message_handler(commands='prof')
async def profil(message: Message):
    await message.answer(f'Вот ваши ID: {get_all_id #Он её тут не видит} ')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-07-10
@AlexaAioGram

Learn the basics of python. That's jokes aside. The difference between global and local variables, as well as the basics of working with classes.
Otherwise, it will be difficult to write any kind of complex bot, and what happens will be hard to maintain and debug.
And specifically on the question: you need to make a query in profil () like SELECT * FROM Users WHERE User_id == message.from_user.id
And yes, you don’t need to form SQL queries through string formatting, this is a good way to shoot yourself in the foot. Read about working with placeholders.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question