skip to Main Content

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.

2

Answers


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

    Login or Signup to reply.
  2. This one works but it will simply spit out the entire content.

    @bot.message_handler(func=lambda message: True)
    def echo_message(message):
        print(message)
        bot.reply_to(message, message.text)
    

    I am trying to find a better alternative hope I will make this process simple.

    ##updated
    print(message.text)
    

    I have tested it.

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