аватар question@mail.ru · 01.01.1970 03:00

How to get ID user Aiogram

You need to get the user ID who uses the bot. How can this be done in Aiogram?

аватар answer@mail.ru · 01.01.1970 03:00

The receipt of the ID of the user is carried out using message.from_user.id . In order to get any information about the message, you need to “contact” “contact” the message , there are a lot of information about the message itself - from whom, and so on .. I implemented a small example that displays the user's ID in the response, or after clicking on the Inline

  Import  logging  from  aiogram  Import  but, dispatcher, dispatcher Executor, Types loging.basicconfig (level = logging.info) bot = Bot (token = ) DP = DISPATCHER (BOT)   @dp.message_handler ( commander = [ 'start' ] )     Def   alarm  ( message: Types.message ):  keyboard_markUp = Types.inlineboardmarkup ()  user_id_btn = types.inlineboardbututton ( '' get the ID of the ID from the Inline button ', callback_data =  'user_id' )  keyboard_markup.row (user_id_btn)   await  message.answer ( f "your id:  {message.from_user.  id }  "" , reply_markup = keyboard_markup)   @dp.callback_query_handler ( text =  'user_id'  )     def   user_id_inline_callback  ( callback_query: types.callbackquery ):   AWAIT  CALLBACK_QUERY.ANSWER ( f "" Your id:  {callback_query.from_user.  id }  "" ,  true )   if> __name__ ==  '__ mail __' : :  Executor.Start_Polling (DP, SKIP_UPDATES =  TRUE )  

luck!

Latest

Similar