Answer the question
In order to leave comments, you need to log in
Error 'message' is not defined what could be the problem?
there is a handler
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
bot.send_message(message.from_user.id, f'Здравствуйте {message.from_user.first_name}Добро пожаловать в наш магазин детской одежды!')
markup = telebot.types.InlineKeyboardMarkup(row_width=1)
button1 = telebot.types.InlineKeyboardButton(text=' Контакты',
callback_data='contacts')
button2 = telebot.types.InlineKeyboardButton(text=' Адреса',
callback_data='address')
button3 = telebot.types.InlineKeyboardButton(text=' Поиск товара по номеру',
callback_data='search')
markup.add(button1, button2, button3)
bot.send_message(chat_id=message.chat.id,
text='Выберите один из команд ниже',reply_markup=markup)
register_user(message.from_user.id, message.from_user.username,
message.from_user.first_name, message.from_user.last_name)
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
if call.data == 'contacts':
bot.send_message(chat_id=<b>message.chat.id</b>,
text='Контакты',reply_markup=markup)
print('press button "contacts"')
if call.data == 'address':
print('press button "address"')
if call.data == 'search':
print('press button "search"')
Answer the question
In order to leave comments, you need to log in
Because the message variable is not defined. you need to start from call
call.message.chat.id
massage.chat.id = id of the chat where the message was sent from.
call.message.chat.id = id of the chat where the callback was sent from.
you don’t receive a message here, but the callback
call.message.chat.id is what you need
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question