如何给qq上传文件
#588
Replies: 2 comments 4 replies
-
|
你可以直接 call api,data 就按照 api 的 body 填写 dict,不需要 message segment |
Beta Was this translation helpful? Give feedback.
2 replies
-
|
我上传QQ群文件同样遇到了问题,不清除是怎么回事,希望大佬可以解答一下! 现象:
环境:Lagrange.OneBot + Nonebot 源代码如下:test = on_command("test", priority=5, block=True)
@test.handle()
async def _(bot:Bot):
group_id = 812564723
file_path = "test.txt"
# 转换为绝对路径
file_path = str(Path(file_path).absolute())
if not Path(file_path).exists():
await send_group_file(bot, group_id, file_path, "test.txt", "/")
else:
await test.send("文件不存在!")
async def send_group_file(bot: Bot, group_id: int, file_path, name: str, folder):
file = Path(file_path).as_uri()
data = {
"group_id": group_id,
"file": file,
"name": name,
"folder": folder
}
logger.info(f"上传文件接口参数==>{data}")
await bot.call_api("upload_group_file", data=data)DEBUG级别日志如下:点击展开09-30 17:06:29 [SUCCESS] nonebot | OneBot V11 1234567890 | [message.group.normal]: Message 437521109 from 9876543210@[群:123123123] '/test'
09-30 17:06:29 [DEBUG] nonebot | Checking for matchers in priority 0...
09-30 17:06:29 [DEBUG] nonebot | Checking for matchers in priority 1...
09-30 17:06:29 [DEBUG] nonebot | Checking for matchers in priority 3...
09-30 17:06:29 [DEBUG] nonebot | Checking for matchers in priority 4...
09-30 17:06:29 [DEBUG] nonebot | Checking for matchers in priority 5...
09-30 17:06:29 [INFO] nonebot | Event will be handled by Matcher(type='message', module=src.plugins.plugin_test, lineno=35)
09-30 17:06:29 [DEBUG] nonebot | Running Matcher(type='message', module=src.plugins.plugin_test, lineno=35)
09-30 17:06:29 [DEBUG] nonebot | Running handler Dependent(call=_)
09-30 17:06:29 [INFO] plugin_test | 上传文件接口参数==>{'group_id': 123123123, 'file': 'file:///E:/Code/python/Project_VSCode/QQrobot/test.txt', 'name': 'test.txt', 'folder': '/'}
09-30 17:06:29 [DEBUG] nonebot | Running CallingAPI hooks...
09-30 17:06:29 [DEBUG] nonebot | OneBot V11 | Calling API upload_group_file
09-30 17:06:29 [INFO] nonebot | Matcher(type='message', module=src.plugins.plugin_test, lineno=35) running complete
09-30 17:06:29 [ERROR] nonebot | Running Matcher(type='message', module=src.plugins.plugin_test, lineno=35) failed.
Traceback (most recent call last):
File "E:\Code\python\Project_VSCode\QQrobot\bot.py", line 45, in <module>
nonebot.run()
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\nonebot\__init__.py", line 337, in run
get_driver().run(*args, **kwargs)
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\nonebot\drivers\fastapi.py", line 187, in run
uvicorn.run(
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\uvicorn\main.py", line 579, in run
server.run()
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\uvicorn\server.py", line 66, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 640, in run_until_complete
self.run_forever()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 321, in run_forever
super().run_forever()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 607, in run_forever
self._run_once()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1922, in _run_once
handle._run()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\nonebot\utils.py", line 254, in run_coro_with_shield
return await coro
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\nonebot\message.py", line 506, in check_and_run_matcher
await _run_matcher(
> File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\nonebot\message.py", line 458, in _run_matcher
await matcher.run(bot, event, state, stack, dependency_cache)
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 926, in run
await self.simple_run(bot, event, state, stack, dependency_cache)
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 863, in simple_run
await handler(
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\nonebot\dependencies\__init__.py", line 113, in __call__
return await cast(Callable[..., Awaitable[R]], self.call)(**values)
File "E:\Code\python\Project_VSCode\QQrobot\src\plugins\plugin_test.py", line 43, in _
await send_group_file(bot, group_id, file_path, "test.txt", "/")
File "E:\Code\python\Project_VSCode\QQrobot\src\plugins\plugin_test.py", line 57, in send_group_file
await bot.call_api("upload_group_file", data=data)
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\nonebot\internal\adapter\bot.py", line 176, in call_api
raise exception
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\nonebot\internal\adapter\bot.py", line 128, in call_api
result = await self.adapter._call_api(self, api, **data)
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\nonebot\adapters\onebot\v11\adapter.py", line 175, in _call_api
return handle_api_result(await self._result_store.fetch(seq, timeout))
File "E:\Code\python\Project_VSCode\QQrobot\QQrobot\Lib\site-packages\nonebot\adapters\onebot\v11\utils.py", line 58, in handle_api_result
raise ActionFailed(**result)
nonebot.adapters.onebot.v11.exception.ActionFailed: ActionFailed(status='failed', retcode=200, data=None, echo='2')
09-30 17:06:29 [DEBUG] nonebot | Stop event propagation
09-30 17:06:29 [DEBUG] nonebot | Checking for matchers completed |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment





Uh oh!
There was an error while loading. Please reload this page.
-
我用的是Lagrange.OneBot + nonebot,我现在遇到一个问题,我想把本地的文件上传到qq群里,我不知道该怎么上传,我的理解是如果是oneBot基础的接口是可以直接调用bot.call_api获取信息,如果是扩展接口,是不是就得自己写post请求啊,比如说我现在这个上传文件的接口就需要手动写一个post请求去调用,是这样的意思吗,有没有大佬救救


Beta Was this translation helpful? Give feedback.
All reactions