nonebot / nonebot2

跨平台 Python 异步聊天机器人框架 / Asynchronous multi-platform chatbot framework written in Python
https://nonebot.dev
MIT License
6.04k stars 561 forks source link

Bug: 使用消息ID获取不到消息内容 #2936

Closed ForElysia-Emen closed 1 month ago

ForElysia-Emen commented 1 month ago

操作系统

Linux

Python 版本

3.9.15

NoneBot 版本

2.0.0b5

适配器

nonebot-adapter-onebot 2.1.3

协议端

napcat 2.2.36

描述问题

我在调试反撤回插件,发现使用消息ID获取不到消息内容。

recall_message_content = await bot.get_msg(message_id=recall_message_id)
logger.error(f"ID:{recall_message_id}\n消息:{recall_message_content}")

日志打印的json中message为空

 'message': [],

完整代码如下

# 检测撤回消息
@if_withdraw.handle()
async def if_withdraw_handle(bot: Bot, event: GroupRecallNoticeEvent):
    if event.notice_type == "group_recall":
        # 获取撤回用户的群昵称
        recall_user_name = await bot.get_group_member_info(group_id=event.group_id, user_id=event.user_id)
        recall_user_name = recall_user_name["card"]
        # 获取撤回用户的QQ昵称
        if recall_user_name == "":
            recall_user_name = await bot.get_stranger_info(user_id=event.user_id)
            recall_user_name = recall_user_name["nickname"]
        # 获取群聊名称
        group_name = await bot.get_group_info(group_id=event.group_id)
        group_name = group_name["group_name"]
        # 获取撤回消息的消息id
        recall_message_id = event.message_id
        # 获取撤回消息的消息内容
        recall_message_content = await bot.get_msg(message_id=recall_message_id)
        logger.error(f"ID:{recall_message_id}\n消息:{recall_message_content}")
        message_segments = []
        for segment_dict in recall_message_content['message']:
            if segment_dict['type'] == 'image':
                segment = MessageSegment.image(segment_dict['data']['url'])
            else:
                segment = MessageSegment(type=segment_dict['type'], data=segment_dict['data'])
            message_segments.append(segment)
        logger.error(f"收到撤回消息:{message_segments}")
        # 将撤回消息发送给所有超级用户
        for superuser in bot.config.superusers:
            await bot.send_private_msg(
                user_id=superuser,
                message=MessageSegment.text(f"{recall_user_name} ({event.user_id}) \n在群聊\n {group_name} ({event.group_id})\n撤回了一条消息\n撤回消息内容:\n") + message_segments
            )

复现步骤

发送测试消息后撤回

期望的结果

No response

截图或日志

09-07 23:27:56 [INFO] nonebot | Matcher <Matcher from basic_plugins.chat_history.chat_message, type=message, priority=1, temp=False> running complete
{'time': 1725722876, 'self_id': 3825923451, 'post_type': 'message', 'sub_type': 'normal', 'user_id': 3962xxxxx4, 'message_type': 'group', 'message_id': 488940349, 'message': [{'type': 'text', 'data': {'text': '测试'}}], 'original_message': [{'type': 'text', 'data': {'text': '测试'}}], 'raw_message': '测试', 'font': 14, 'sender': {'user_id': 3962xxxxxx4, 'nickname': '温酒', 'sex': None, 'age': None, 'card': '求求你们别肝了', 'area': None, 'level': None, 'role': 'admin', 'title': None}, 'to_me': False, 'reply': None, 'group_id': 12xxxxx990, 'anonymous': None, 'real_id': 488940349, 'message_format': 'array', 'message_seq': 488940349}
09-07 23:27:56 [INFO] nonebot | Matcher <Matcher from my_plugins.intercept_withdraw, type=message, priority=1, temp=False> running complete
09-07 23:27:56 [INFO] nonebot | Event will be handled by <Matcher from plugins.fudu, type=message, priority=999, temp=False>
09-07 23:27:56 [INFO] nonebot | Matcher <Matcher from plugins.fudu, type=message, priority=999, temp=False> running complete
09-07 23:27:58 [SUCCESS] nonebot | ONEBOT V11 3825923451 | [notice.group_recall]: {'time': 1725722878, 'self_id': 3825923451, 'post_type': 'notice', 'notice_type': 'group_recall', 'user_id': 396216064, 'group_id': 129706990, 'operator_id': 396216064, 'message_id': 488940349}
09-07 23:27:58 [INFO] nonebot | Event will be handled by <Matcher from basic_plugins.admin_bot_manage.update_group_member_info, type=notice, priority=1, temp=False>
09-07 23:27:58 [INFO] nonebot | Event will be handled by <Matcher from basic_plugins.group_handle, type=notice, priority=1, temp=False>
09-07 23:27:58 [INFO] nonebot | Event will be handled by <Matcher from basic_plugins.group_handle, type=notice, priority=1, temp=False>
09-07 23:27:58 [INFO] nonebot | Event will be handled by <Matcher from my_plugins.intercept_withdraw, type=notice, priority=1, temp=False>
09-07 23:27:58 [INFO] nonebot | Matcher <Matcher from basic_plugins.admin_bot_manage.update_group_member_info, type=notice, priority=1, temp=False> running complete
09-07 23:27:58 [INFO] nonebot | Matcher <Matcher from basic_plugins.group_handle, type=notice, priority=1, temp=False> running complete
09-07 23:27:58 [INFO] nonebot | Matcher <Matcher from basic_plugins.group_handle, type=notice, priority=1, temp=False> running complete
09-07 23:27:58 [ERROR] services | ID:488940349
消息:{'self_id': 3825923451, 'user_id': 396216064, 'time': 1725722876, 'message_id': 488940349, 'message_seq': 488940349, 'real_id': 488940349, 'message_type': 'group', 'sender': {'user_id': 396xxxxx64, 'nickname': '温酒', 'card': '求求你们别肝了', 'role': 'admin'}, 'raw_message': '', 'font': 14, 'sub_type': 'normal', 'message': [], 'message_format': 'array', 'post_type': 'message', 'group_id': 1xxxxxx0}
09-07 23:27:58 [ERROR] services | 收到撤回消息:[]
yanyongyu commented 1 month ago

这个问题与nb无关,请去协议端询问