T
T
Ty3_KpecTu2021-07-07 17:04:55
Python
Ty3_KpecTu, 2021-07-07 17:04:55

Error IndentationError: unexpected unindent, what should I do?

I tried to create a telegram bot
here is the code

import telebot;
bot = telebot.TeleBot('####');
message_handler(content_types=['text'])
def get_text_messages(message):
    @bot.message_handler(content_types=['text', 'document', 'audio'])
if message.text == "Привет":
    bot.send_message(message.from_user.id, "Привет, чем я могу тебе помочь?")
elif message.text == "/help":
    bot.send_message(message.from_user.id, "Напиши привет")
else:
    bot.send_message(message.from_user.id, "Я тебя не понимаю. Напиши /help.")
bot.polling(none_stop=True, interval=0)

I must say right away that I don’t know python well.
when I run it in the console, it gives an error:
File "C:\Users\maksb\Desktop\Bot\bot.py", line 6
if message.text == "Hello":
IndentationError: unexpected unindent
Please help :(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Krostelev, 2021-07-07
@twistfire92

You did something with the arrangement of decorators. Learn the basics of the language first.

import telebot
bot = telebot.TeleBot('####')

@bot.message_handler(content_types=['text'])
def get_text_messages(message): 
    if message.text == "Привет":
        bot.send_message(message.from_user.id, "Привет, чем я могу тебе помочь?")
    elif message.text == "/help":
        bot.send_message(message.from_user.id, "Напиши привет")
    else:
        bot.send_message(message.from_user.id, "Я тебя не понимаю. Напиши /help.")

bot.polling(none_stop=True, interval=0)

M
Maxim Siomin, 2021-07-07
@MaxSiominDev

def get_text_messages(message):
    @bot.message_handler(content_types=['text', 'document', 'audio'])
    if message.text == "Привет":
        bot.send_message(message.from_user.id, "Привет, чем я могу тебе помочь?")
    elif message.text == "/help":
        bot.send_message(message.from_user.id, "Напиши привет")
    else:
        bot.send_message(message.from_user.id, "Я тебя не понимаю. Напиши /help.")
    bot.polling(none_stop=True, interval=0)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question