简体   繁体   English

discord.py 我如何在 discord.py 中制作齿轮?

[英]discord.py How i make cogs in discord.py?

i can't use cogs in discord.py. He gives me this error:我不能在 discord.py 中使用 cogs。他给了我这个错误:

RuntimeWarning: coroutine 'BotBase.load_extension' was never awaited
bot.load_extension(f"cogs.{file[:-3]}")

And when i make this:当我这样做时:

await bot.load_extension(f"cogs.{file[:-3]}")

then gives me this error:然后给我这个错误:

`SyntaxError: 'await' outside function`

Code:代码:

for file in os.listdir(f"./cogs"):    
    if file.endswith(".py"):
        bot.load_extension(f"cogs.{file[:-3]}")

Thanks for help感谢帮助

Try to put that code inside an async function.尝试将该代码放入异步 function 中。

async def your_function(...):
    for file in os.listdir(f"./cogs"):    
        if file.endswith(".py"):
            await bot.load_extension(f"cogs.{file[:-3]}")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM