小编Haz*_*kel的帖子

python 电报机器人“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)
    
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)

python bots telegram

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

bots ×1

python ×1

telegram ×1