【问题标题】:aiogram message handler not firing for a message containing mediaaiogram 消息处理程序未针对包含媒体的消息触发
【发布时间】:2021-04-25 09:09:58
【问题描述】:

我正在使用 aiogram 2.11.2 作为 Telegram API 的 Python 接口,但我在最简单的回调中遇到了一个问题:它在消息仅为文本时会激活,但在附加任何媒体时会失败。这包括照片、视频、音频、贴纸和 GIF,有或没有标题。

我希望我不会错过什么。

import aiogram


class TelegramBot(object):
    def __init__(self):
        self.bot = aiogram.Bot(token="TOKEN")
        self.dispatcher = aiogram.Dispatcher(bot=self.bot)
        self.dispatcher.register_message_handler(self.on_msg,)
    
    async def on_msg(self, msg: aiogram.types.Message):
        print("Message received in telegram")

【问题讨论】:

    标签: python python-telegram-bot


    【解决方案1】:

    原来我真的错过了一些东西。要监听各种消息,将content_type定义为

    dispatcher.register_message_handler(self.on_msg, content_type=aiogram.types.ContentType.all())
    

    感谢answerer to my Git issue

    【讨论】:

      猜你喜欢
      • 2021-02-07
      • 1970-01-01
      • 1970-01-01
      • 2022-10-24
      • 1970-01-01
      • 1970-01-01
      • 2014-02-26
      • 2012-09-15
      • 1970-01-01
      相关资源
      最近更新 更多