I am creating a Telegram bot using pytelegrambotapi
. But when I test the code, my Telegram Bot always replies with quoting my input like this, I don’t want it to quote my input message but send the message directly.
Also how can I get replies by just using simple Hi
or Hello
not /hi
or /hello
.
My Code:
import telebot
import time
bot_token = ''
bot= telebot.TeleBot(token=bot_token)
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message, 'Hi')
@bot.message_handler(commands=['help'])
def send_welcome(message):
bot.reply_to(message, 'Read my description')
while True:
try:
bot.polling()
except Exception:
time.sleep(10)
2
Answers
If i understood corectly:
cid = message.chat.id
bot.send_message(cid, "Hello")
bot.reply_to
replies to the message itself. If you wish to send a separate message, usebot.send_message
. You’ll need to pass the ID of the user you’re wishing to send a message to. You can find this id onmessage.chat.id
so you’re sending the message to the same chat.Instead off using a
message_handler
with acommands=['help']
you can remove the parameter to catch each message not catched by any command message handler.Example with above implemented:
Visual result: