GraiaProject / Application

一个设计精巧, 协议实现完备的, 基于 mirai-api-http 的即时聊天软件自动化框架.
https://graia-document.vercel.app/
GNU Affero General Public License v3.0
438 stars 63 forks source link

使用文档的示例代码可以回复消息,但 python 控制台报错 #117

Closed vcheckzen closed 3 years ago

vcheckzen commented 3 years ago

描述你遇到的问题:

使用文档的示例代码可以回复消息,但 graia 控制台报错

复现步骤: 该 BUG 会在进行以下操作后出现:

  1. 运行文档示例代码

发生错误的代码

from graia.broadcast import Broadcast
from graia.application import GraiaMiraiApplication, Session
from graia.application.message.chain import MessageChain
import asyncio

from graia.application.message.elements.internal import Plain
from graia.application.friend import Friend

loop = asyncio.get_event_loop()

bcc = Broadcast(loop=loop)
app = GraiaMiraiApplication(
    broadcast=bcc,
    connect_info=Session(
        host="http://localhost:3333",  # 填入 httpapi 服务运行的地址
        authKey="IkITKEYgoQNJDm4",  # 填入 authKey
        account=xxxxxxxx,  # 你的机器人的 qq 号
        websocket=True  # Graia 已经可以根据所配置的消息接收的方式来保证消息接收部分的正常运作.
    )
)

@bcc.receiver("FriendMessage")
async def friend_message_listener(app: GraiaMiraiApplication, friend: Friend):
    await app.sendFriendMessage(friend, MessageChain.create([
        Plain("Hello, World!")
    ]))

app.launch_blocking()

控制台日志输出截图:

2021-04-04 13:20:43 I/main: Auto-login xxxxxxxxx
2021-04-04 13:20:43 I/Bot.xxxxxxxxx: Logging in...
2021-04-04 13:20:44 I/Bot.xxxxxxxxx: No OtherClient online.
2021-04-04 13:20:44 I/Bot.xxxxxxxxx: Login successful
2021-04-04 13:20:44 I/main: mirai-console started successfully.
2021-04-04 13:23:01 V/Bot.xxxxxxxxx: Name(xxxxxxxxx) -> 你好
2021-04-04 13:23:01 V/Bot.xxxxxxxxx: Friend(xxxxxxxxx) <- Hello, World!
Traceback (most recent call last):
  File ".venv\lib\site-packages\graia\broadcast\__init__.py", line 201, in Executor
    result = await run_always_await_safely(
  File ".venv\lib\site-packages\graia\broadcast\utilles.py", line 31, in run_always_await_safely
    return callable(*args, **kwargs)
  File ".venv\lib\site-packages\graia\application\__init__.py", line 237, in logger_friend_message
    message_string=event.messageChain.asSerializationString().__repr__(),
  File ".venv\lib\site-packages\graia\application\message\chain.py", line 396, in asSerializationString
    result.append(e.asSerializationString())
AttributeError: 'Element' object has no attribute 'asSerializationString'
[2021-04-04 13:22:27,164][INFO]: [BOT xxxxxxxxx] Friend(xxxxxxxxx) <- 'Hello, World!'

运行环境:

OasisAkari commented 3 years ago

pydantic降到1.6.1就好了