@
@
@eingod2017-11-27 11:36:49
PHP
@eingod, 2017-11-27 11:36:49

How to fix callable Telegram Api Bot error in Python?

When you click "Select product" an error occurs and the bot stops what's wrong? :(

import telebot
#from telebot import *
from telebot import types
import config

bot = telebot.TeleBot(config.token)
@bot.message_handler(commands=['start'])
def send_welcome(message):
    markup = types.ReplyKeyboardMarkup(True)
    markup.add('Томск', 'Новосибирск')
    msg = bot.send_message(message.chat.id, 'Выбери город', reply_markup=markup)
    bot.register_next_step_handler(msg, choose_city)
def choose_city(message):
    if (message.text == 'Томск'):
        markup = types.ReplyKeyboardMarkup(True)
        markup.add('Выбрать товар')
        markup.add('Главное меню')
        msg = bot.send_message(message.chat.id, 'Томск. Нажми выбрать товар', reply_markup=markup)
        bot.register_next_step_handler(msg, 'choose_tsk, menu')

    elif (message.text == 'Новосибирск'):
        markup = types.ReplyKeyboardMarkup(True)
        markup.add('Выбрать товар')
        markup.add('Главное меню')
        msg = bot.send_message(message.chat.id, 'Новосибирск. Нажми выбрать товар', reply_markup=markup)
        bot.register_next_step_handler(msg, 'choose_nsk, menu')
@bot.message_handler(regexp='Главное меню')
def menu(message):
        markup = types.ReplyKeyboardMarkup(True)
        markup.row('Томск', 'Новосибирск')
        msg = bot.send_message(message.chat.id, 'Главное меню, выберите город', reply_markup=markup)
        bot.register_next_step_handler(msg, choose_city)

@bot.message_handler(regexp='Томск')
def choose_tsk(message):
    if (message.text == 'Выбрать товар'):
        markup = types.ReplyKeyboardMarkup(True)
        markup.add('Ягоды')
        markup.add('Главное меню')
        msg = bot.send_message(message.chat.id, 'Томск. Выберите товар из списка', reply_markup=markup)
        msg()
@bot.message_handler(regexp='Новосибирск')
def choose_nsk(message):
    if (message.text == 'Выбрать товар'):
        markup = types.ReplyKeyboardMarkup(True)
        markup.add('Ягоды')
        markup.add('Главное меню')
        msg = bot.send_message(message.chat.id, 'Новосибирск. Выберите товар из списка', reply_markup=markup)
        msg()


bot.polling(none_stop=True)

Mistake
"C:\Program Files\Python36-32\python.exe" "C:/my programms/bot telega/test 1.py"
2017-11-27 15:34:02,408 (util.py:64 WorkerThread2) ERROR - TeleBot: "TypeError occurred, args=("'str' object is not callable",)
Traceback (most recent call last):
File "C:\Program Files\Python36-32\lib\site-packages\telebot\util.py", line 58, in run
task(*args, **kwargs)
TypeError: 'str' object is not callable
"
Traceback (most recent call last):
File "C:/my programms/bot telega/test 1.py", line 52, in
bot.polling(none_stop=True)
File "C:\Program Files\Python36-32\lib\site-packages\telebot\__init__.py", line 264, in polling
self.__threaded_polling(none_stop, interval, timeout)
File "C:\Program Files\Python36-32\lib\site-packages\telebot\__init__.py", line 288, in __threaded_polling
2017-11-27 15:34:02,413 (util.py:64 WorkerThread1) ERROR - TeleBot: "TypeError occurred, args=("'str' object is not callable",)
Traceback (most recent call last):
File "C:\Program Files\Python36-32\lib\site-packages\telebot\util.py", line 58, in run
task(*args, **kwargs)
TypeError: 'str' object is not callable
"
self.worker_pool.raise_exceptions()
File "C:\Program Files\Python36-32\lib\site-packages\telebot\util.py", line 107, in raise_exceptions
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
File "C:\Program Files\Python36-32\lib\site-packages\six.py", line 693, in reraise
raise value
File "C:\Program Files\Python36-32\lib\site-packages\telebot\util.py", line 58, in run
task(*args, **kwargs)
TypeError: 'str' object is not callable
Process finished with exit code 1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lander, 2019-09-10
@leni_m

You need to know recursion .
When you know, you will need to write a function that:
1. Determines if there is a next nesting level and if there is, then selects this level and calls itself with this level.
2. If there is no next level, then returns the content from the current level.

V
Viktor Korop, 2017-11-27
@DarkWizardUa

Because you do not have a response to such a message, and you also need to put a handler before the choose_city function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question