简体   繁体   English

如何为 discord.py 中的命令分组并在不同的齿轮中使用它们?

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

I am working on a bot and I want the commands of the bot to be added to different groups but I don't know how to make group.我正在开发一个机器人,我希望将机器人的命令添加到不同的组,但我不知道如何创建组。

Is there a way to make the group in the main bot file and then use it in cogs?有没有办法在主 bot 文件中创建组,然后在 cogs 中使用它?

I think you know how to create them with this example.我想你知道如何用这个例子来创建它们。

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


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

The part of invoke_without_command=True will make sure the commands aren't double executed. invoke_without_command=True的部分将确保命令不会被重复执行。

The command in this code would be {prefix}system hello此代码中的命令将是 {prefix}system hello

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

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