Python电报机器人发送带有动作的消息
我在python 3中使用python telegram bot库,我编写了以下代码:Python电报机器人发送带有动作的消息,python,python-3.x,bots,telegram,telegram-bot,Python,Python 3.x,Bots,Telegram,Telegram Bot,我在python 3中使用python telegram bot库,我编写了以下代码: from telegram import * from telegram.ext import * bot.send_chat_action(chat_id=update.message.chat_id , action = telegram.ChatAction.TYPING) bot.sendMessage(chat_id=update.message.chat_id, text="Hi") 此代码将
from telegram import *
from telegram.ext import *
bot.send_chat_action(chat_id=update.message.chat_id ,
action = telegram.ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text="Hi")
此代码将正确地向客户端发送消息,但我希望当bot向客户端发送消息时,客户端屏幕的上方(在电报信使中)显示but正在键入…
。
我在sendMessage方法中使用action=telegram.ChatAction.TYPING
作为选项,
但它不起作用,我也找不到我的问题。
任何指南?问题在于库,请编写
导入电报
,而不是从电报导入*编写,以确保用户可以看到聊天动作
,在调用聊天动作
方法后,您需要等待几秒钟的时间延迟:
from telegram import *
from telegram.ext import *
from time import sleep
from random import random
bot.sendChatAction(chat_id=update.message.chat_id ,
action = telegram.ChatAction.TYPING)
sleep(random() * 2 + 3.)
bot.sendMessage(chat_id=update.message.chat_id, text="Hi")
什么是法规?当您在电报中键入某些文本时,将显示“键入…”文本。