tencent-connect / botpy

QQ频道机器人PythonSDK
MIT License
613 stars 94 forks source link

狗屁不通的错误提示 #178

Open CubicStone31 opened 8 months ago

CubicStone31 commented 8 months ago

使用api.get_channels时提示“频道末对机器人末授权”。请问究竟是需要授权还是不需要授权? 另外,即使在机器人权限中把所有权限都打开,还是会出现此错误。

示例报错如下 [ERROR] (http.py:76)_handle_response [botpy] 接口请求异常,请求连接: https://api.sgroup.qq.com/guilds/10290137413427843821/channels, 错误代码: 400, 返回内容: {'message': '频道末对机器人末授权', 'code': 11264, 'err_code': 40012009, 'trace_id': '51b47340e42f1bb52031c3c14cdbe5b3'}, trace_id:51b47340e42f1bb52031c3c14cdbe5b3 Traceback (most recent call last): File "/Users/cubicstone31/Desktop/Crypto/lib/python3.12/site-packages/botpy/client.py", line 285, in _run_event await coro(*args, **kwargs) File "/Users/cubicstone31/Desktop/Crypto/work/qqbot.py", line 26, in on_direct_message_create await self.api.get_channels(guild_id=message.guild_id) File "/Users/cubicstone31/Desktop/Crypto/lib/python3.12/site-packages/botpy/api.py", line 328, in get_channels return await self._http.request(route) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/cubicstone31/Desktop/Crypto/lib/python3.12/site-packages/botpy/http.py", line 190, in request return await _handle_response(response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/cubicstone31/Desktop/Crypto/lib/python3.12/site-packages/botpy/http.py", line 85, in _handle_response raise ServerError(message) from None # adding from None to prevent chain exception being raised ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

触发问题的代码: class MyClient(botpy.Client): async def on_ready(self): _log.info(f"robot 「{self.robot.name}」 on_ready!")

async def on_direct_message_create(self, message: DirectMessage):
    # await self.api.post_dms(
    #     guild_id=message.guild_id,
    #     content=f"机器人{self.robot.name}收到你的私信了: {message.content}",
    #     msg_id=message.id,
    # )

    await self.api.get_channels(guild_id=message.guild_id)
chaunsin commented 5 months ago

使用api.get_channels时提示“频道末对机器人末授权”。请问究竟是需要授权还是不需要授权? 另外,即使在机器人权限中把所有权限都打开,还是会出现此错误。

示例报错如下 [ERROR] (http.py:76)_handle_response [botpy] 接口请求异常,请求连接: https://api.sgroup.qq.com/guilds/10290137413427843821/channels, 错误代码: 400, 返回内容: {'message': '频道末对机器人末授权', 'code': 11264, 'err_code': 40012009, 'trace_id': '51b47340e42f1bb52031c3c14cdbe5b3'}, trace_id:51b47340e42f1bb52031c3c14cdbe5b3 Traceback (most recent call last): File "/Users/cubicstone31/Desktop/Crypto/lib/python3.12/site-packages/botpy/client.py", line 285, in _run_event await coro(*args, **kwargs) File "/Users/cubicstone31/Desktop/Crypto/work/qqbot.py", line 26, in on_direct_message_create await self.api.get_channels(guild_id=message.guild_id) File "/Users/cubicstone31/Desktop/Crypto/lib/python3.12/site-packages/botpy/api.py", line 328, in get_channels return await self._http.request(route) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/cubicstone31/Desktop/Crypto/lib/python3.12/site-packages/botpy/http.py", line 190, in request return await _handle_response(response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/cubicstone31/Desktop/Crypto/lib/python3.12/site-packages/botpy/http.py", line 85, in _handle_response raise ServerError(message) from None # adding from None to prevent chain exception being raised ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

触发问题的代码: class MyClient(botpy.Client): async def on_ready(self): _log.info(f"robot 「{self.robot.name}」 on_ready!")

async def on_direct_message_create(self, message: DirectMessage):
    # await self.api.post_dms(
    #     guild_id=message.guild_id,
    #     content=f"机器人{self.robot.name}收到你的私信了: {message.content}",
    #     msg_id=message.id,
    # )

    await self.api.get_channels(guild_id=message.guild_id)

我使用golang sdk也碰到了这个问题,也很是困惑

dan-kuroto commented 1 month ago

我之前也碰到这个报错,最后发现是我guild_id传错了……

一开始试过QQ频道里那个pd开头的频道号,也试过机器人平台配置频道ID的时候显示的那个数字频道号,但那两个都不是guild_id……

获取用户频道列表 这个接口查到的id才是真正的guild_id……