nonebot / adapter-qq

NoneBot2 QQ 适配器 / QQ adapter for nonebot2
MIT License
210 stars 18 forks source link

无法连接 #35

Closed YuYue-Amatsuki closed 1 year ago

YuYue-Amatsuki commented 1 year ago

已确认appid token secret填写正确 尝试过重置token 仍无法正常链接 日志如下

03-14 12:52:37 [SUCCESS] nonebot | NoneBot is initializing...
03-14 12:52:37 [INFO] nonebot | Current Env: dev
03-14 12:52:37 [DEBUG] nonebot | Loaded Config: {'driver': '~fastapi+~websockets+~httpx', 'host': IPv4Address('127.0.0.1'), 'port': 9090, 'log_level': 'DEBUG', 'api_timeout': 30.0, 'superusers': set(), 'nickname': set(), 'command_start': {'/'}, 'command_sep': {'.'}, 'session_expire_timeout': datetime.timedelta(seconds=120), 'fastapi_reload': False, 'qqguild_bots': [{'id': '102****21', 'token': 'V7S******f7neEM', 'secret': 'bA******xxiJfr', 'intent': {'guild_messages': True, 'at_messages': False}}], 'environment': 'dev'}
03-14 12:52:38 [DEBUG] nonebot | Succeeded to load adapter "QQ Guild"
03-14 12:52:39 [SUCCESS] nonebot | Succeeded to import "echo"
03-14 12:52:39 [SUCCESS] nonebot | Running NoneBot...
03-14 12:52:39 [DEBUG] nonebot | Loaded adapters: QQ Guild
03-14 12:52:39 [INFO] uvicorn | Started server process [9408]
03-14 12:52:39 [INFO] uvicorn | Waiting for application startup.
03-14 12:52:39 [DEBUG] nonebot | QQ Guild | QQ Guild run in sandbox mode: False
03-14 12:52:39 [DEBUG] nonebot | QQ Guild | QQ Guild api base url: https://api.sgroup.qq.com/
03-14 12:52:39 [DEBUG] nonebot | QQ Guild | Calling API shard_url_get
03-14 12:52:39 [INFO] uvicorn | Application startup complete.
03-14 12:52:39 [INFO] uvicorn | Uvicorn running on http://127.0.0.1:9090 (Press CTRL+C to quit)
03-14 12:52:40 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://api.sgroup.qq.com/websocket established
03-14 12:52:40 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 12:52:40 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 12:52:43 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://api.sgroup.qq.com/websocket established
03-14 12:52:43 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 12:52:43 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 12:52:46 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://api.sgroup.qq.com/websocket established
03-14 12:52:46 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 12:52:46 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 12:52:47 [INFO] uvicorn | Shutting down
03-14 12:52:47 [INFO] uvicorn | Waiting for application shutdown.
03-14 12:52:47 [INFO] uvicorn | Application shutdown complete.
03-14 12:52:47 [INFO] uvicorn | Finished server process [9408]
he0119 commented 1 year ago

看起来可能是鉴权出错了。

Identify 客户端发送鉴权 Invalid Session 当identify或resume的时候,如果参数有错,服务端会返回该消息 https://bot.q.qq.com/wiki/develop/api/gateway/opcode.html#opcode

YuYue-Amatsuki commented 1 year ago

看起来可能是鉴权出错了。

Identify 客户端发送鉴权 Invalid Session 当identify或resume的时候,如果参数有错,服务端会返回该消息 https://bot.q.qq.com/wiki/develop/api/gateway/opcode.html#opcode

所以这是tx那边的问题(?

he0119 commented 1 year ago

不好说,你可以再检查一下配置。我刚才试了一下没问题。

yanyongyu commented 1 year ago

你的bot是私域还是公域

YuYue-Amatsuki commented 1 year ago

你的bot是私域还是公域

私域

yanyongyu commented 1 year ago

你试试打开沙箱环境配置

YuYue-Amatsuki commented 1 year ago

你试试打开沙箱环境配置

打开后仍然无法连接 日志如下



03-14 14:00:30 [SUCCESS] nonebot | NoneBot is initializing...
03-14 14:00:30 [INFO] nonebot | Current Env: dev
03-14 14:00:30 [DEBUG] nonebot | Loaded Config: {'driver': '~fastapi+~websockets+~httpx', 'host': IPv4Address('127.0.0.1'), 'port': 9090, 'log_level': 'DEBUG', 'api_timeout': 30.0, 'superusers': set(), 'nickname': set(), 'command_start': {'/'}, 'command_sep': {'.'}, 'session_expire_timeout': datetime.timedelta(seconds=120), 'environment': 'dev', 'qqguild_is_sandbox': True, 'qqguild_bots': [{'id': '102041021', 'token': 'V7SF******6uf7neEM', 'secret': 'b******qxxiJfr', 'intent': {'guild_messages': True, 'at_messages': False}}], 'fastapi_reload': False}
03-14 14:00:31 [DEBUG] nonebot | Succeeded to load adapter "QQ Guild"
03-14 14:00:32 [SUCCESS] nonebot | Succeeded to import "echo"
03-14 14:00:32 [SUCCESS] nonebot | Running NoneBot...
03-14 14:00:32 [DEBUG] nonebot | Loaded adapters: QQ Guild
03-14 14:00:32 [INFO] uvicorn | Started server process [15616]
03-14 14:00:32 [INFO] uvicorn | Waiting for application startup.
03-14 14:00:32 [DEBUG] nonebot | QQ Guild | QQ Guild run in sandbox mode: True
03-14 14:00:32 [DEBUG] nonebot | QQ Guild | QQ Guild api base url: https://sandbox.api.sgroup.qq.com
03-14 14:00:32 [DEBUG] nonebot | QQ Guild | Calling API shard_url_get
03-14 14:00:33 [INFO] uvicorn | Application startup complete.
03-14 14:00:33 [INFO] uvicorn | Uvicorn running on http://127.0.0.1:9090 (Press CTRL+C to quit)
03-14 14:00:33 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://sandbox.api.sgroup.qq.com/websocket established
03-14 14:00:33 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 14:00:33 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 14:00:36 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://sandbox.api.sgroup.qq.com/websocket established
03-14 14:00:36 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 14:00:36 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 14:00:39 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://sandbox.api.sgroup.qq.com/websocket established
03-14 14:00:39 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 14:00:39 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 14:00:43 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://sandbox.api.sgroup.qq.com/websocket established
03-14 14:00:43 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 14:00:43 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 14:00:43 [INFO] uvicorn | Shutting down
03-14 14:00:44 [INFO] uvicorn | Waiting for application shutdown.
03-14 14:00:44 [INFO] uvicorn | Application shutdown complete.
03-14 14:00:44 [INFO] uvicorn | Finished server process [15616]
yanyongyu commented 1 year ago

要不再检查下app id token secret 😂 看不出来什么问题

或者到 打印一下payload https://github.com/nonebot/adapter-qqguild/blob/cfb4370ffab367718e6dab3d18464a0ad0571372/nonebot/adapters/qqguild/adapter.py#L237

yanyongyu commented 1 year ago

打印下payload看看有没有具体信息

YuYue-Amatsuki commented 1 year ago

打印下payload看看有没有具体信息

具体如何操作?🤔

yanyongyu commented 1 year ago

就是我上面发的那个代码位置加个print payload就行了

yanyongyu commented 1 year ago

看了下你直接把nb的日志等级改成trace就可以了

YuYue-Amatsuki commented 1 year ago

看了下你直接把nb的日志等级改成trace就可以了

日志如下

03-14 22:16:47 [SUCCESS] nonebot | NoneBot is initializing...
03-14 22:16:47 [INFO] nonebot | Current Env: dev
03-14 22:16:47 [DEBUG] nonebot | Loaded Config: {'driver': '~fastapi+~websockets+~httpx', 'host': IPv4Address('127.0.0.1'), 'port': 9090, 'log_level': 'TRACE', 'api_timeout': 30.0, 'superusers': set(), 'nickname': set(), 'command_start': {'/'}, 'command_sep': {'.'}, 'session_expire_timeout': datetime.timedelta(seconds=120), 'qqguild_is_sandbox': True, 'fastapi_reload': False, 'qqguild_bots': [{'id': '102041021', 'token': 'V7SFRR*******HjGm6uf7neEM', 'secret': 'bAZ*******xiJfr', 'intent': {'guild_messages': True, 'at_messages': False}}], 'environment': 'dev'}
03-14 22:16:48 [TRACE] nonebot | Detected driver <class 'nonebot.drivers.fastapi.Driver'> with mixins [<class 'nonebot.drivers.websockets.Mixin'>, <class 'nonebot.drivers.httpx.Mixin'>].
03-14 22:16:48 [DEBUG] nonebot | Succeeded to load adapter "QQ Guild"
03-14 22:16:50 [TRACE] nonebot | Define new matcher Matcher(type='message', module=nonebot.plugins.echo)
03-14 22:16:50 [SUCCESS] nonebot | Succeeded to import "echo"
03-14 22:16:50 [SUCCESS] nonebot | Running NoneBot...
03-14 22:16:50 [DEBUG] nonebot | Loaded adapters: QQ Guild
03-14 22:16:50 [INFO] uvicorn | Started server process [5996]
03-14 22:16:50 [INFO] uvicorn | Waiting for application startup.
03-14 22:16:50 [DEBUG] nonebot | QQ Guild | QQ Guild run in sandbox mode: True
03-14 22:16:50 [DEBUG] nonebot | QQ Guild | QQ Guild api base url: https://sandbox.api.sgroup.qq.com
03-14 22:16:50 [DEBUG] nonebot | QQ Guild | Calling API shard_url_get
03-14 22:16:50 [INFO] uvicorn | Application startup complete.
03-14 22:16:50 [INFO] uvicorn | Uvicorn running on http://127.0.0.1:9090 (Press CTRL+C to quit)
03-14 22:16:50 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://sandbox.api.sgroup.qq.com/websocket established
03-14 22:16:50 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 22:16:50 [TRACE] nonebot | QQ Guild | Received payload: InvalidSession(opcode=<Opcode.INVALID_SESSION: 9>, d=False)
03-14 22:16:50 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 22:16:54 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://sandbox.api.sgroup.qq.com/websocket established
03-14 22:16:54 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 22:16:54 [TRACE] nonebot | QQ Guild | Received payload: InvalidSession(opcode=<Opcode.INVALID_SESSION: 9>, d=False)
03-14 22:16:54 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 22:16:57 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://sandbox.api.sgroup.qq.com/websocket established
03-14 22:16:57 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 22:16:57 [TRACE] nonebot | QQ Guild | Received payload: InvalidSession(opcode=<Opcode.INVALID_SESSION: 9>, d=False)
03-14 22:16:57 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 22:17:00 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://sandbox.api.sgroup.qq.com/websocket established
03-14 22:17:00 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 22:17:00 [TRACE] nonebot | QQ Guild | Received payload: InvalidSession(opcode=<Opcode.INVALID_SESSION: 9>, d=False)
03-14 22:17:00 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 22:17:00 [INFO] uvicorn | Shutting down
03-14 22:17:00 [INFO] uvicorn | Waiting for application shutdown.
03-14 22:17:00 [INFO] uvicorn | Application shutdown complete.
03-14 22:17:00 [INFO] uvicorn | Finished server process [5996]
yanyongyu commented 1 year ago

这。。。tx服务器也没有发送任何有效信息啊。没法判断到底是啥原因。好怪

YuYue-Amatsuki commented 1 year ago

这。。。tx服务器也没有发送任何有效信息啊。没法判断到底是啥原因。好怪

🤔确实很奇怪 在下午6点多的时候倒是成功连接上了 现在又不行了

yanyongyu commented 1 year ago

问题是否解决了呢?

moian98 commented 1 year ago

我也遇到这样的问题了。 通过nb创建项目时,项目文件夹里只有3个文件:.env.pordpyproject.tomlREADME.md,加一个虚拟环境的.venv文件夹。 不知道是不是这里的问题?没有bot.py这个入口文件。。。

yanyongyu commented 1 year ago

和入口文件没有关系

moian98 commented 1 year ago

和入口文件没有关系

找到原因了,我的是公域机器人,把配置里的guild_messages设置为false就好了。

koking0 commented 7 months ago

我也遇到类似的问题了,这些intent是啥意思呀。

he0119 commented 7 months ago

我也遇到类似的问题了,这些intent是啥意思呀。

https://bot.q.qq.com/wiki/develop/api-v2/dev-prepare/interface-framework/event-emit.html#%E4%BA%8B%E4%BB%B6%E8%AE%A2%E9%98%85intents

koking0 commented 7 months ago

找到原因了,intent设置为下面这样才可以:

{
      "guilds": true,
      "guild_members": true,
      "guild_messages": false,
      "guild_message_reactions": true,
      "direct_message": true,
      "open_forum_event": true,
      "audio_live_member": true,
      "c2c_group_at_messages": false,
      "interaction": true,
      "message_audit": true,
      "forum_event": false,
      "audio_action": true,
      "at_messages": true
    }

为什么guild_messages和c2c_group_at_messages不能设置为true呢?

yanyongyu commented 7 months ago

guild_messages仅私域频道机器人可用,c2c_group_at_messages仅企业群机器人可用

koking0 commented 7 months ago

guild_messages仅私域频道机器人可用,c2c_group_at_messages仅企业群机器人可用

OK