Answer the question
In order to leave comments, you need to log in
Error NameError: name 'message' is not defined, what should I do?
import telebot
import config
from telebot import types
bot = telebot.TeleBot(config.token)
@bot.message_handler(commands=['start'])
def welcome(message):
sti = open('static/welcome.webp', ' rb')
bot.send_sticker(message.chat.id, sti)
bot.send_message(message.chat.id, "Welcome to MamaiDrugs auto sales bot. Please select a city." format(message.from_user, bot.get_me( )),)
# Prepare the buttons
keyboard = types.InlineKeyboardMarkup()
# Prepare the text and handler for each zodiac sign
in turn key_oven = types.InlineKeyboardButton(text='Moscow', callback_data='city')
# And add the button to the screen
keyboard .add(key_oven)
key_telec = types.InlineKeyboardButton(text='Peter', callback_data='zodiac')
keyboard.add(key_telec)
key_bliznecy = types.InlineKeyboardButton(text='Novosibirsk', callback_data='zodiac')
keyboard.add(key_bliznecy)
key_rak = types.InlineKeyboardButton(text='Yekaterinburg', callback_data='zodiac')
keyboard.add(key_rak)
key_lev = types.InlineKeyboardButton(text='Kazan', callback_data='zodiac')
keyboard.add(key_lev)
key_deva = types. InlineKeyboardButton(text='Novgorod', callback_data='zodiac')
keyboard.add(key_deva)
key_vesy = types.InlineKeyboardButton(text='Chelyabinsk', callback_data='zodiac')
keyboard.add(key_vesy)
key_scorpion = types.InlineKeyboardButton(text='Omsk', callback_data='zodiac')
keyboard.add(key_scorpion)
key_strelec = types.InlineKeyboardButton(text='Samara', callback_data='zodiac')
keyboard.add(key_strelec)
key_kozerog = types.InlineKeyboardButton(text='Rostov', callback_data='zodiac')
keyboard.add(key_kozerog)
key_vodoley = types.InlineKeyboardButton(text='Ufa', callback_data='zodiac')
keyboard.add(key_vodoley)
key_ryby = types. InlineKeyboardButton(text='Krasnoyarsk', callback_data='zodiac')
keyboard.add(key_ryby)
# Show all buttons at once and write a message about selection
bot.send_message(message.from_user.id, text='Choose your zodiac sign', reply_markup=keyboard)
@bot.message_handler(content_types=['text'])
def lalala(message):
bot.send_message(message.chat.id, message.text)
# RUN
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question