G
G
gforsee2021-04-27 21:23:05
Python
gforsee, 2021-04-27 21:23:05

A simple telegram bot. Error with pytelegrambotapi, don't understand what is the problem?

import telebot
import config

from telebot import types

bot = telebot.TeleBot(config.TOKEN)

@bot.message_handler(commands=['start'])
def lalala(message):
  bot.send_message(message.chat.id, "привет".format(message.from_user, bot.get_me()),
    parse_mode='html', reply_markup=markup)


  # keyboard
  markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
  item1 = types.KeyboardButton("от ppp")
  item2 = types.KeyboardButton("от ooo")

  markup.add(item1, item2)



@bot.message_handler(content_types=['text'])
def lalala(message):
  if message.chat.type == 'private':
    if message.text == 'от ppp':
      bot.send_message(message.chat.id, 'Отлично! Ты подписан на уведомления от ppp')
    elif message.text == 'от ooo':
      bot.send_message(message.chat.id, 'Отлично! Ты подписан на уведомления от ooo')
    else:
      bot.send_message(message.chat.id, 'Я не знаю что ответить ')


# RUN
bot.polling(none_stop=True)


ERROR Traceback

(most recent call last):
File "E:\New folder\bot.py", line 35, in
bot.polling(none_stop=True)
File "C:\Users\vadim\AppData\Roaming\Python\ Python38\site-packages\telebot\__init__.py", line 496, in polling
self.__threaded_polling(none_stop, interval, timeout, long_polling_timeout)
File "C:\Users\vadim\AppData\Roaming\Python\Python38\site-packages \telebot\__init__.py", line 555, in __threaded_polling
raise e
File "C:\Users\vadim\AppData\Roaming\Python\Python38\site-packages\telebot\__init__.py", line 518, in __threaded_polling
self. worker_pool.raise_exceptions()
File "C:\Users\vadim\AppData\Roaming\Python\Python38\site-packages\telebot\util.py", line 117, in raise_exceptions
raise self.exception_info
File "C:\Users\vadim\AppData\Roaming\ Python\Python38\site-packages\telebot\util.py", line 69, in run
task(*args, **kwargs)
File "E:\New folder\bot.py", line 11, in lalala
parse_mode=' html', reply_markup=markup)
UnboundLocalError: local variable 'markup' referenced before assignment

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-04-27
@gforsee

That the variable is not defined. First they used it, only then they announced it.
608856de446ad693076586.jpeg
Block with create variable higher raise than send message

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question