Discord.py如何以异步方法的形式从其他模块调用同步方法?

How to call sync methods from other module In the form of async method in Discord.py?

我想在discord.py中使用完全异步的Python Twitch API模块,如果不可能或者需要很长时间,请介绍完整的替代异步模块。

asyncio 不禁止在 async 函数中使用 sync 函数,所以你可以在 discord.py 事件中使用你的库

import asyncio

# Synchronous function
def say_sync(string):
  print(string)

# Asynchronous function
async def async_function():
  say_sync("Hello")
  await asyncio.sleep(1) # Sleep for 1 second
  say_sync("world!")

asyncio.run(async_function()) # Run async function

Live Example