S
S
szjyakgf2022-02-02 12:43:56
Python
szjyakgf, 2022-02-02 12:43:56

How to pass user_id to button?

Bot on aiogram
Works in chat and you need to make it so that the buttons can be pressed by the one to whom the response to the command is addressed

@dp.message_handler(commands=['id'])
async def id(message: types.Message):
    user_id = message.from_user.id
    keyboard = types.InlineKeyboardMarkup()
    callback_button1 = types.InlineKeyboardButton(text="Текст", callback_data="button1")
    keyboard.add(callback_button1)
    await message.reply(f"ID чата: {message.chat.id}", reply_markup=keyboard)

and in the callbackhandler I will check the id from the button and who presses
how to put the id into the button?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2022-02-02
@szjyakgf

callback_data='<ID>|button1'
then just got it from the user_id button
user_id, data = call.data.split('|')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question