Home python Telegram Bot does not respond to commands. Python / Telebot

Telegram Bot does not respond to commands. Python / Telebot




I use the TELEBOT library under Python, for writing a Telegram Bot. I refactorly manage the script and found that the bot stopped responding to teams. When you try to enter ‘START’, ‘START’, use any other teams that support the control script, nothing happens.

The interpreter did not highlight any errors, I am sure that the problem may hide in the get_message_bot function or in the decorator @ Bot.Message_Handler (Commands = [‘Start’, ‘Refresh’]). Some of them picked up the introduced string, but this does not happen.

This is not a problem on the side of Telegram. The first version of the control script “responds” to the command and works correctly. Unfortunately, I could not see the error myself, I am inexperienced.

import telbot
From Telebot Import Types
Token = 'I do not want to fool my token'
# Getting text that enters the user
# Section of crutches: command check '/ Team'
@ Bot.Message_Handler (Content_Types = ['Text'])
Def Response (Message):
  Get_Message_Bot = Message.Text.Strip (). Lower ()
@ Bot.callback_Query_Handler (Func = Lambda C: True)
DEF INLN (InButton):
  If inbutton.data == 'Rescue':
    Main (InButton.Message)
  if inbutton.data == 'sos':
    SOS (InButton.Message)
#Main menu
@ Bot.Message_Handler (Commands = ['Menu'])
Def Main (Message):
 # Deleted the code not to race post
  bot.send_message (message.chat.id, MainText, Reply_markup = Markup) # Bot will throw data into chat, alas, here you need a crutch
  If get_message_bot == 'Sell':
    NEWLOT (Message)
  if get_message_bot == 'profile':
    Profile (Message)
# Is displayed when you first start the bot '/ start'
# Displayed when restarting the bot '/ Refresh'
@ Bot.Message_Handler (Commands = ['Start', 'Refresh'])
Def Start (Message):
  #ATTENTION! It is necessary to check according to the database
  # If the user is registered early, with the command / Start we give full access
  starttext = message.from_user.first_name +, "Welcome to Markeples! Let's start your profile - without it, you will not be able to use the service."
  starttext2 = message.from_user.first_name +, "You can see the available commands at any time. Dial / Help If you suddenly disappear buttons - this team will definitely help"
  starttext3 = "This option is not available now. Authorize."
  Markup = Types.ReplyKeyboardMarkup (Resize_Keyboard = True, Row_Width = 1)
  Entry_BTN1 = Types.KeyboardButton ('Create Profile')
  Entry_BTN2 = Types.KeyboardButton ('Get Help')
  entry_btn3 = Types.KeyboardButton ('I have a profile')
  Markup.Add (entry_btn1, entry_btn2, entry_btn3)
  Bot.Send_Message (Message.chat.id, StartText1, Reply_MarkUp = Markup)
  Bot.Send_Message (Message.chat.id, StartText2, Reply_MarkUp = Markup)
  If get_message_bot == "I have a profile":
    Main (Message)
  If Get_Message_Bot == "Get Help" OR Get_Message_Bot == "/ Support":
    Support (Message)
    Bot.Send_Message (Message.chat.id, StartText3) #ELSE can work incorrectly
@ Bot.Message_Handler (Commands = ['List'])
  HELPTEXT = '' '/ START - Main Menu
/ Support - Support
/ SOS - Write a moderator
/ Arbitry - Arbitration
/ Profile - Edit Profile
/ Lots - View lots
/ setLot - Lot Lot
/ Promo - View Shares ''
  Helptext2 = 'Did you disappear from the screen? Click below to restore! '
  Bot.Send_Message (Message.chat.id, Helptext)
  ListkeyBoard = Types.inlineKeyboardMarkup ()
  keyboard.add (Types.inlineKeyboardButton (Text = 'Return buttons', callback_data = 'rescue'))
  Bot.Send_Message (Message.chat.ID, HelpText2, Reply_Markup = ListKeyboard)
Bot.Polling (None_Stop = True)

Answer 1, Authority 100%

Colleagues, I appeal to everyone who will come to this page. The problem has a solution. On stackoverflow a bunch of posts with the same question, but without an answer. Experimental, I solved my problem.

If you have a decorator that processes the user text:

@ bot.message_handler (content_types = ['text'])
Def Response (Message):
   Get_Message_Bot = Message.Text.Strip (). Lower ()

then it must be at the very bottom of your code (of course, before Bot.polling ()).
Any code that is recorded below for this decorator (except for Bot.Polling ()) will not be executed.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions