Answer the question
In order to leave comments, you need to log in
Telegram bot shows its data on from_user. What to do?
I am learning how to write telegram bots. Here is this piece of code:
elif call.data=='id':
bot.send_message(call.message.chat.id, F'Твой ID: {call.message.from_user.id}')
elif call.data=='nick':
bot.send_message(call.message.chat.id, f'Твой Nickname: {call.message.from_user.first_name}, {call.message.from_user.last_name}')
Answer the question
In order to leave comments, you need to log in
call.message - the initial message in which the user pressed the button. Of course, the author of this message is a bot.
Call.from_user should be used instead of call.message.from_user.
The idea of using call.message.chat.id to get the user id will only work as long as it is used in a private chat with the user, where chat_id is always equal to user_id. This will not work in group chats.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question