loop attribute cannot be accessed in non-async contexts. Consider using either an asynchronous main function and passing it to asyncio.run or using asynchronous initialisation hooks such as Client.setup_hook File "C:\Users\Administrator\Desktop\examples\postA.py", line 24, in <module> client.loop.create_task(send_message()) ^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: loop attribute cannot be accessed in non-async contexts. Consider using either an asynchronous main function and passing it to asyncio.run or using asynchronous initialisation hooks such as Client.setup_hook
时间: 2023-11-13 13:52:29 浏览: 563
这个错误是因为你在非异步上下文中尝试访问 loop 属性。你可以使用 asyncio.run() 来运行异步函数,或使用异步初始化钩子如 Client.setup_hook()。如果你的代码中有很多异步任务,建议使用 async/await 语法和 asyncio 库来处理异步操作。这样可以避免一些常见的错误和异常。
阅读全文