Answer the question
In order to leave comments, you need to log in
Why is the bot not working?
Hello, I wrote a code for the translate command, the bot receives the word along with the command and gives the translation of the word. I did it through the messages.text.split construction, but the bot outputs that "I didn't understand the word". Where is the mistake?
#Обработчик команды /translate
@bot.message_handler(commands=["translate"])
def translate(message):
try:
word = message.text.split(maxsplit=1)[1]
worden = translator.translate(word, dest='en')
finword = worden.text
bot.send_message(message.chat.id, finword)
except:
bot.send_message(message.chat.id, "Не понял слова")
Answer the question
In order to leave comments, you need to log in
Handle the exception correctly, it's not even clear to you what the error is.
Replace at least except with:
except Exception as err:
print(str(err))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question