[英]python telegram bot "context.bot.send_message"
我正在使用“python-telegram-bot”庫,並且一直在互聯網上查看各種示例。
我注意到在對話中有兩種回復方式:
第一個:''' context.bot.send_message(chat_id=update.effective_chat.id, text=msg)'''
第二個:'''update.message.reply_text(text=msg)'''
實際上他們都工作。 我應該更喜歡一個嗎? 說明我的問題。 在 echo 函數第 3 行和第 4 行給出相同的結果
回復功能
def echo(update, context):
msg='Hi, nice to see you!'
context.bot.send_message(chat_id=update.effective_chat.id, text=msg)
update.message.reply_text(text=msg)
主要功能::
def main():
updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher
echo_handler=MessageHandler()
echo_handler = MessageHandler(Filters.text & (~Filters.command), echo)
dispatcher.add_handler(echo_handler)
updater.start_polling()
enter code here
我認為“context.bot.send_message”更適用於來自作業的消息,因為您可以粘貼上下文。 以此為例: https : //github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/timerbot.py
update.message.reply_text
將是對現有消息的回復。 它會引用它。 context.bot.send_message
將是一條新消息。 它不會與直接回復相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.