簡體   English   中英

discord.py 我如何在 discord.py 中制作齒輪?

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

我不能在 discord.py 中使用 cogs。他給了我這個錯誤:

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

當我這樣做時:

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

然后給我這個錯誤:

`SyntaxError: 'await' outside function`

代碼:

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

感謝幫助

嘗試將該代碼放入異步 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