Search code examples
pythontelegrampy-telegram-bot-api

How to have the message text showed up in my command line?


I use pytelegrambotapi library to make my bot in telegram.

Here is my code:

import config
import telebot

bot = telebot.TeleBot(config.token)


@bot.message_handler(commands=['start'])
def handle_start_message(message):
    bot.send_message(message.chat.id, "Hello. I'm your bot")
    print(message.text)

What I want to do is to return the message text in my command line. It returns nothing, however, the bot is working since it answers me in telegram.


Solution

  • Most probably, the code is running in separate Tread/Process, which does not have access to the console, and hence, not able to print something in it.

    Use logging to file instead of print.

    Here is a useful link - https://github.com/python-telegram-bot/python-telegram-bot#logging