Haz*_*kel 8 python bots telegram
我正在使用“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)
Run Code Online (Sandbox Code Playgroud)
主功能::
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
Run Code Online (Sandbox Code Playgroud)
小智 2
我认为“context.bot.send_message”更适合来自作业的消息,因为您可以粘贴上下文。以此为例: https: //github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/timerbot.py
| 归档时间: |
|
| 查看次数: |
10668 次 |
| 最近记录: |