M
M
Max2019-05-31 17:26:01
Python
Max, 2019-05-31 17:26:01

Error in PyCharm, does not start the bot, what should I do?

Here is the code:

@bot.message_handler(commands=['start'])
def start_message(message):
    bot.send_message(message.chat.id, 'Привет, я бот', reply_markup=keyboard())

@bot.message_handler(content_types=['text'])
def send_text(message):
    if message.text.lower() == 'Купить':
        bot.send_message(message.chat.id, '''Товар 1
        Товар 2
        Товар 3''')
    elif message.text.lower() == 'Рулетка':
        bot.send_message(message.chat.id, 'Ты выиграл приз!')

def keyboard(): #клавиатура купить/рулетка
    markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
    btn1 = types.KeyboardButton('Рулетка')
    btn2 = types.KeyboardButton('Купить')
    markup.add(btn1, btn2)

bot.polling()

First, pycharm throws this error:
C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\python.exe: can't open file 'bot.py': [Errno 2] No such file or directory
Secondly, the bot does not process @bot.message_handler(content_types=['text']) commands when I run it through the built-in IDLE, what should I do about it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bbkmzzzz, 2019-05-31
@bbkmzzzz

bot.message_handler(content_types=['text'])

if your script file is named bot.py - rename it, there should be no name conflict

E
Elvis, 2019-05-31
@Dr_Elvis

Of course he won't work. You take the text of the message, convert it to lower case, and then compare it to the text with the first letter in upper case.
And on the first question, they wrote to you above

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question