我正在使用python-telegram-api编写一个电报机器人组管理员,我想让我的机器人回复组like this中的消息,但我能用它得到的唯一类似的东西是this。有没有像第一张图片那样回复消息的方法?
from telegram.ext import (Updater, CommandHandler, MessageHandler,
Filters, ConversationHandler)
import telegram
import logging
telegram_token = "BOT TOKEN"
updater = Updater(token=telegram_token, use_context=True);
dispatcher = updater.dispatcher;
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %
(message)s', level=logging.INFO);
def mesgs_hand(update, context):
if(update.message.text == "Hi"):
context.bot.forward_message(chat_id=update.effective_chat.id,
from_chat_id=update.effective_chat.id,
message_id=update.message.message_id, text="Hey there!");
#this method forwards the message but without adding 'Hey there!'
elif(update.message.text == "Hello"):
context.bot.send_message(chat_id=update.message.chat_id, text="Hello!");
#this method just replies to the message without forwarding
messages_handler = MessageHandler(Filters.text, mesgs_hand)
dispatcher.add_handler(messages_handler)
def bot():
updater.start_polling();
if __name__ == "__main__":
bot();发布于 2019-12-02 02:56:52
您可以在send_message函数中使用reply_to_message_id参数:
def mesgs_hand(update, context):
if(update.message.text == "Hi"):
context.bot.send_message(
chat_id=update.message.chat_id,
reply_to_message_id=update.message.message_id,
text="Hey there!")https://stackoverflow.com/questions/59127269
复制相似问题