簡體   English   中英

如何為 discord.py 中的命令分組並在不同的齒輪中使用它們?

[英]How do I make groups for commands in discord.py and use them in different cogs?

我正在開發一個機器人,我希望將機器人的命令添加到不同的組,但我不知道如何創建組。

有沒有辦法在主 bot 文件中創建組,然后在 cogs 中使用它?

我想你知道如何用這個例子來創建它們。

@client.group(name='system', invoke_without_command=True)
async def system():
    pass


@system.command(name='load')
async def hello_subcommand():
    print('test')

invoke_without_command=True的部分將確保命令不會被重復執行。

此代碼中的命令將是 {prefix}system hello

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM