-2

I'm new to Pycharm but as a beginner, I know I get "Process finished with exit code 0" which means that My code doesn't have any error, but the code is running only 2 seconds. Could you guys help me out, please? Much appreciate it!

D:\TelegramBots\venv\Scripts\python.exe D:/TelegramBots/main.py

Bot started...

Process finished with exit code 0

Image sample

import Constants as Keys
from telegram.ext import *
import Responses as R

print("Bot started...")


def start_command(update, context):
    update.message.reply_text('Type something to get started!')


def help_command(update, context):
    update.message.reply_text('If you need help you should ask Google!')


def handle_command(update, context):
    text = str(update.message.text).lower()
    response = R.sample_responses(text)

    update.message.reply_text(response)


def error(update, context):
    print(f"Update {update} caused error {context.error}")


def main():
    updater = Updater(Keys.API_KEY, use_context=True)
    dp = Updater.dispatcher

    dp.add_handler(CommandHandler("start", start_command))
    dp.add_handler(CommandHandler("help", help_command))

    dp.add_handler(CommandHandler(Filters.text, start_command))

    dp.add_error_handler(error)

    updater.start_polling(10)
    updater.idle()

    main()

2 Answers2

0

Your file is only defining functions so it runs and then doesn’t perform any of them.

Where you call main() (line 41) do not indent and your program will run as expected.

Eno Gerguri
  • 639
  • 5
  • 22
  • you can check that I have called main() to the bot API, but still the same `def main(): updater = Updater(Keys.API_KEY, use_context=True) dp = Updater.dispatcher` – blackdevil Aug 04 '21 at 15:11
0

I removed the space in front of main() in the last line, now it's working