Answer the question
In order to leave comments, you need to log in
How to get user id / chat id telebot?
There is a code for a telegram bot (Telebot or pyTelegramBotApi).
@bot.message_handler(commands=['start'])
def start_message(message):
bot.send_message(message.chat.id, 'test')
Answer the question
In order to leave comments, you need to log in
body = '{message}\n' \
'--\n' \
'{first}, {last}\n' \
'{username}, {id}'.format(message=message.text, first=message.from_user.first_name,
last=message.from_user.last_name, username=message.from_user.username,
id=message.chat.id)
message.from_user.id is more correct, because in groups, message.chat.id will return the group ID, not the specific user. But if you are sure that the case will be limited only to dialogues (private messages), then message.chat.id is also appropriate.
@bot.message_handler(commands=['start'])
def start_message(message):
your_variable = message.from_user.id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question