Ljzd-PRO / nonebot-plugin-mystool

QQ聊天、频道机器人插件 | 米游社工具-每日米游币任务、游戏签到、商品兑换、免抓包登录、原神崩铁便笺提醒
https://pypi.org/project/nonebot-plugin-mystool
MIT License
420 stars 52 forks source link

qq频道私信始终失败 #236

Closed JaniQuiz closed 8 months ago

JaniQuiz commented 11 months ago

我使用qq频道的发送私信命令的时候发现始终不发送消息,但是机器人会回复已经发送私信,于是我进行了分析,插入日志后发现这里的event.user_id()为str类型,但是后面的event.guild_id也是str类型,而我查了下这个send_private_msg函数需要的guild_id类型为int,传入参数的类型不对。麻烦注意一下。 image 然后我进行了强制类型转换,添加了个int,发现还是同样不发消息,但回复已经发送成功,我在send_private_msg发现这个guild_id=int(event.guild_id) if isinstance(event, MessageCreateEvent) else None会自动走到else,导致传入的guild_id还是空的,我又把if后的语句注释掉后,发现传入的参数正常了,但是却报错<ActionFailed: 500, code=305001, message=backend error, trace_id=5320c623cd581766696806e737aaac08> image image image image 我去官网查了下报错,发现正好跳过了这个报错,根本没有305001,想问下是怎么回事?有解决方法吗?

JaniQuiz commented 11 months ago

详细报错信息: Traceback (most recent call last): File "", line 17, in File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot__init__.py", line 331, in run get_driver().run(*args, *kwargs) File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\drivers\fastapi.py", line 201, in run uvicorn.run( File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\uvicorn\main.py", line 587, in run server.run() File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\uvicorn\server.py", line 61, in run return asyncio.run(self.serve(sockets=sockets)) File "C:\Users\30869\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run return loop.run_until_complete(main) File "C:\Users\30869\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 633, in run_until_complete self.run_forever() File "C:\Users\30869\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 321, in run_forever super().run_forever() File "C:\Users\30869\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 600, in run_forever self._run_once() File "C:\Users\30869\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 1896, in _run_once handle._run() File "C:\Users\30869\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 80, in _run self._context.run(self._callback, self._args) File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\message.py", line 476, in check_and_run_matcher await _run_matcher( File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\message.py", line 428, in _run_matcher await matcher.run(bot, event, state, stack, dependency_cache) File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 846, in run await self.simple_run(bot, event, state, stack, dependency_cache) File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 821, in simple_run await handler( File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\dependencies__init.py", line 113, in call__ return await cast(Callable[..., Awaitable[R]], self.call)(**values) File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot_plugin_mystool\usercheck.py", line 225, in send_result, action_failed = await send_private_msg(

File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot_plugin_mystool\utils.py", line 423, in send_private_msg dms: DMS = await bot.post_dms(recipient_id=user_id, source_guild_id=guild_id) File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 123, in call_api raise exception File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 98, in call_api result = await self.adapter._call_api(self, api, data) File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\adapters\qq\adapter.py", line 416, in _call_api return await api_handler(bot, data) File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\adapters\qq\utils.py", line 64, in call return await self.func(inst, *args, **kwds) File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\adapters\qq\bot.py", line 1042, in post_dms return parse_obj_as(DMS, await self._request(request)) File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\adapters\qq\bot.py", line 549, in _request return self._handle_response(response) File "C:\Users\30869\Desktop\LittleSanyue.venv\lib\site-packages\nonebot\adapters\qq\bot.py", line 538, in _handle_response raise ActionFailed(response) nonebot.adapters.qq.exception.ActionFailed: <ActionFailed: 500, code=305001, message=backend error, trace_id=5320c623cd581766696806e737aaac08>

JaniQuiz commented 11 months ago

应该就是这两行的问题,具体我不太了解这个适配器,也没见着个文档啥的 image

JaniQuiz commented 11 months ago

抱歉,写得有点长了 44C67981 ,麻烦您认真看下

Ljzd-PRO commented 11 months ago

我的话是提示发送私信失败,但是实际上是有成功发送的

Ljzd-PRO commented 11 months ago

应该就是这两行的问题,具体我不太了解这个适配器,也没见着个文档啥的 image

有一些参数可能要参考腾讯的文档

Ljzd-PRO commented 11 months ago
⚠️发送私信失败,错误信息:<ActionFailed: 202, code=304023, message=push message is waiting for audit now, data={'message_audit': {'audit_id': '7a16d693-c3d4-4de6-9c83-1f6e914344f4'}}>

看起来是说等待审核,实际上发送成功,内容就是 /帮助 返回的内容。

SaYa-t commented 11 months ago
⚠️发送私信失败,错误信息:<ActionFailed: 202, code=304023, message=push message is waiting for audit now, data={'message_audit': {'audit_id': '7a16d693-c3d4-4de6-9c83-1f6e914344f4'}}>

看起来是说等待审核,实际上发送成功,内容就是 /帮助 返回的内容。

我是主动推送的时候提示nonebot.adapters.qq.exception.ActionFailed: <ActionFailed: 500, code=305001, message=backend error, trace_id=6c1790356e459646fbf4ba34988a0646>

dontdot commented 11 months ago
12-06 09:35:46 [ERROR] nonebot_plugin_mystool | QQGuild 尝试主动发送私信消息失败。频道ID:233*********24,用户ID:12***********29,消息内容:
❕您的洞天财瓮已经满啦
❖原神·实时便笺❖
🆔账户 764******
⏳树脂数量:87 / 160
⏱️树脂将在12-06 19:18回满
🕰️探索派遣:5 / 5
📅每日委托:4 个任务未完成
💰洞天财瓮:2400 / 2400
🎰参量质变仪:N/A
Traceback (most recent call last):
  File "<string>", line 21, in <module>
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\nonebot\__init__.py", line 331, in run
    get_driver().run(*args, **kwargs)
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\nonebot\drivers\fastapi.py", line 201, in run
    uvicorn.run(
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\uvicorn\main.py", line 578, in run
    server.run()
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\uvicorn\server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\asyncio\base_events.py", line 640, in run_until_complete
    self.run_forever()
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\asyncio\base_events.py", line 607, in run_forever
    self._run_once()
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\asyncio\base_events.py", line 1922, in _run_once
    handle._run()
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\apscheduler\executors\base_py3.py", line 30, in run_coroutine_job
    retval = await job.func(*job.args, **job.kwargs)
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\nonebot_plugin_mystool\plan.py", line 632, in auto_note_check
    await genshin_note_check(user=user, user_ids=user_ids)
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\nonebot_plugin_mystool\plan.py", line 506, in genshin_note_check
    await send_private_msg(user_id=user_id, message=msg)
> File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\nonebot_plugin_mystool\utils.py", line 418, in send_private_msg
    dms: DMS = await bot.post_dms(recipient_id=user_id, source_guild_id=guild_id)
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\nonebot\internal\adapter\bot.py", line 123, in call_api
    raise exception
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\nonebot\internal\adapter\bot.py", line 98, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\nonebot\adapters\qq\adapter.py", line 416, in _call_api
    return await api_handler(bot, **data)
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\nonebot\adapters\qq\utils.py", line 64, in __call__
    return await self.func(inst, *args, **kwds)
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\nonebot\adapters\qq\bot.py", line 973, in post_dms
    return parse_obj_as(DMS, await self._request(request))
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\nonebot\adapters\qq\bot.py", line 480, in _request
    return self._handle_response(response)
  File "C:\ProgramData\anaconda3\envs\3y7\Lib\site-packages\nonebot\adapters\qq\bot.py", line 469, in _handle_response
    raise ActionFailed(response)
nonebot.adapters.qq.exception.ActionFailed: <ActionFailed: 500, code=305001, message=backend error, trace_id=adf8e3fb362a08e6ba4c4d41ea7e95c8>

我也305001,实际上没有成功发送私信给我

TomIsFat commented 11 months ago

我也有相同问题,机器人无法私信

TomIsFat commented 11 months ago

我也有相同问题,机器人无法私信

IMG_20231210_175057

Ljzd-PRO commented 11 months ago

频道中使用 /私信响应 可以接收到机器人的私信消息吗

TomIsFat commented 11 months ago

频道中使用 /私信相应 可以接收到机器人的私信消息吗

可以接收到私信消息

Ljzd-PRO commented 11 months ago

主动发送私信需要有群组ID,/私信响应 可以进行一次获取,然后会保存起来。正常情况的话登录操作应该就会保存了

TomIsFat commented 11 months ago

频道中使用 /私信相应 可以接收到机器人的私信消息吗

使用/私信响应 同样会报错,但是可以接受到信息

主动发送私信需要有群组ID,/私信响应 可以进行一次获取,然后会保存起来。正常情况的话登录操作应该就会保存了

感谢解答,我之后再观察一下。另外想请问一下群组ID在plugin_data.json里面叫什么名称?

Ljzd-PRO commented 11 months ago

频道中使用 /私信相应 可以接收到机器人的私信消息吗

使用/私信响应 同样会报错,但是可以接受到信息

主动发送私信需要有群组ID,/私信响应 可以进行一次获取,然后会保存起来。正常情况的话登录操作应该就会保存了

感谢解答,我之后再观察一下。另外想请问一下群组ID在plugin_data.json里面叫什么名称?

qq_guilds

https://github.com/Ljzd-PRO/nonebot-plugin-mystool/blob/ffdb0784cfba2aa76dec5f87abae81d8f27dded9/src/nonebot_plugin_mystool/user_data.py#L381-L382

Ljzd-PRO commented 11 months ago

用户ID不是QQ号

TomIsFat commented 11 months ago

频道中使用 /私信相应 可以接收到机器人的私信消息吗

使用/私信响应 同样会报错,但是可以接受到信息

主动发送私信需要有群组ID,/私信响应 可以进行一次获取,然后会保存起来。正常情况的话登录操作应该就会保存了

感谢解答,我之后再观察一下。另外想请问一下群组ID在plugin_data.json里面叫什么名称?

qq_guilds

https://github.com/Ljzd-PRO/nonebot-plugin-mystool/blob/ffdb0784cfba2aa76dec5f87abae81d8f27dded9/src/nonebot_plugin_mystool/user_data.py#L381-L382

现在解决了,以下是步骤(可能有冗余步骤) 1 让机器人清空账号数据 2 手动删除plugin_data.json里涉及到我的账户的所有数据 3 重新登陆

备注:之前使用过换绑账号功能,不清楚是否有关系,在第二步也删除了原账号,以及原账号和现账号的绑定

Ljzd-PRO commented 9 months ago

目前QQ频道私信已经改成用 nonebot-plugin-send-anything-anywhere 实现了,频道ID也只会储存一个,当使用 /私信响应 命令的时候,储存的频道ID会手动刷新。不知道能不能解决频道私信的问题。

https://github.com/Ljzd-PRO/nonebot-plugin-mystool/releases/tag/v2.0.1-beta.1 (安排到了2.1.0)

Ljzd-PRO commented 9 months ago

目前QQ频道私信已经改成用 nonebot-plugin-send-anything-anywhere 实现了,频道ID也只会储存一个,当使用 /私信响应 命令的时候,储存的频道ID会手动刷新。不知道能不能解决频道私信的问题。

~https://github.com/Ljzd-PRO/nonebot-plugin-mystool/releases/tag/v2.0.1-beta.1~ (安排到了2.1.0)

multi-platform 分支 https://github.com/Ljzd-PRO/nonebot-plugin-mystool/tree/multi-platform

Ljzd-PRO commented 9 months ago

目前QQ频道私信已经改成用 nonebot-plugin-send-anything-anywhere 实现了,频道ID也只会储存一个,当使用 /私信响应 命令的时候,储存的频道ID会手动刷新。不知道能不能解决频道私信的问题。

~https://github.com/Ljzd-PRO/nonebot-plugin-mystool/releases/tag/v2.0.1-beta.1~ (安排到了2.1.0)

发布在 v2.1.0 了 https://github.com/Ljzd-PRO/nonebot-plugin-mystool/releases/tag/v2.1.0