skip to Main Content

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:TelegramBotsvenvScriptspython.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

Answers


  1. Chosen as BEST ANSWER

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


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search