Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python电报机器人发送带有动作的消息_Python_Python 3.x_Bots_Telegram_Telegram Bot - Fatal编程技术网

Python电报机器人发送带有动作的消息

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") 此代码将

我在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")
此代码将正确地向客户端发送消息,但我希望当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")

什么是法规?当您在电报中键入某些文本时,将显示“键入…”文本。