【问题标题】:python telegram bot "context.bot.send_message"python电报机器人“context.bot.send_message”
【发布时间】:2021-02-21 18:18:23
【问题描述】:

我正在使用“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

【问题讨论】:

    标签: python bots telegram


    【解决方案1】:

    我认为“context.bot.send_message”更习惯于来自工作的消息,因为您可以粘贴上下文。 以此为例:https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/timerbot.py

    【讨论】:

      【解决方案2】:

      update.message.reply_text 将是对现有消息的回复。它会引用它。 context.bot.send_message 将是一条新消息。它与直接回复不同。

      【讨论】:

        猜你喜欢
        • 2020-10-28
        • 1970-01-01
        • 2017-08-18
        • 2022-01-01
        • 1970-01-01
        • 2017-09-11
        • 2020-09-25
        • 2018-02-27
        • 2023-03-17
        相关资源
        最近更新 更多