我使用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")发布于 2021-04-26 17:48:21
结果发现我真的错过了一些东西。要侦听所有类型的消息,只需将content_type定义为
dispatcher.register_message_handler(self.on_msg, content_type=aiogram.types.ContentType.all())https://stackoverflow.com/questions/67251651
复制相似问题