D
D
Danil Kolesnikov2022-02-13 19:46:40
Python
Danil Kolesnikov, 2022-02-13 19:46:40

How to create a telegram bot in PyCharm?

I decided to create a telegram bot in PyCharm. Here is the code I wrote:

import telebot

bot = telebot.TeleBot("5227***********************nZ_0c")

@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
    bot.reply_to(message, "Привет, рад тебя видеть! ")

@bot.message_handler(func=lambda message: True)
def echo_all(message):
    if message.text == "привет":
        bot.reply_to(message, "Привет, мой друг")
    elif message.text == "как дела?":
        bot.reply_to(message, "Всё хорошо, как твои дела?")
        if message.text == "как дела":
            bot.reply_to(message, "Отлично, как твои дела?")

        # bot.reply_to(message, message.text)

    bot.infinity_polling()

The program does not give any errors, the code is written correctly, but nothing happens when sending messages to the bot, before writing the second part of the code, when there was just an echo bot, everything worked, the bot answered the same messages that I wrote to him. What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2022-02-13
@bacon

I'm just starting to learn programming, I decided to start by creating a bot in telegram
it's a bad idea to start with a bot, there are a lot of similar questions from people like you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question