Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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 3.x 如何在电报机器人python中检测gif_Python 3.x_Handler_Gif_Content Type_Telegram Bot - Fatal编程技术网

Python 3.x 如何在电报机器人python中检测gif

Python 3.x 如何在电报机器人python中检测gif,python-3.x,handler,gif,content-type,telegram-bot,Python 3.x,Handler,Gif,Content Type,Telegram Bot,各位。我不知道如何在电报中用我的机器人检测GIF。下面的示例是当bot在聊天中检测到文本并且文本为hi时,bot回复hi 我想我可以用内容类型做一些事情,但我不知道 @bot.message_handler(func=lambda message: True) def echo_message(message): if message.text == 'hi' : cid= message.chat.id bot.send_message(cid, 'Hi

各位。我不知道如何在电报中用我的机器人检测GIF。下面的示例是当bot在聊天中检测到文本并且文本为hi时,bot回复hi

我想我可以用内容类型做一些事情,但我不知道

@bot.message_handler(func=lambda message: True)
def echo_message(message):
    if message.text == 'hi' :
        cid= message.chat.id
        bot.send_message(cid, 'Hi')

要检测GIF,您必须在您的应用程序中使用

这将在包含文档的每条消息上运行提供的函数。但请注意,文档可能不仅仅是GIF。这来自文档:

此对象表示一个常规文件,而不是照片、语音和视频文件 信息和音频文件

常规文件(例如.zip归档文件)也被视为文档。为了识别GIF,您需要查找文档的mime_类型。下面是一个示例代码:

def docmsg(bot, update):
   if message.document.mime_type == "video/mp4":
      print("This is a GIF!")

dispatcher.add_handler(MessageHandler(Filters.document, docmsg))
updater.start_polling()
updater.idle()

由于视频未被视为文档,因此常规视频/mp4将不会在此处捕获。但是,电报对所有GIF都使用MP4格式,因此这是一种检测GIF的故障保护方法。

请注意,在您的第一个回答中,电报不仅会检测GIF。其他文档类型的文件,例如PDF文件,也会被检测到。content_types=['document',gif']lane 1336:今天下午我将检查检测PDF是否不担心这太完美了,我现在证明了这一点,谢谢你,很抱歉最后的评论:D非常好的人!