python - 如何为命令 discord.py 分配子帮助?
问题描述
如何为 discord.py 中的命令分配子帮助?
class xkcd(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def hi(self, ctx):
await ctx.send('hey')
当我键入 <!help hi> 时,它应该显示有关该命令的更多信息。我怎样才能做到这一点?
解决方案
根据您要显示的内容和要显示的位置,有几个选项,但我会给出重要的选项。brief
并description
允许您指定命令的简短描述和完整描述。它们是 的参数,@client.command()
将放置在@client.command(HERE)
. 在你的情况下,那将是@commands.command(HERE)
.
补充:正如Taku提到的,该
help
参数还可以让你做你想做的事。@commands.command(help="")
允许您定义帮助消息的长文本,这实际上将同时brief
进行description
。如果您不需要区分两种描述,请使用此选项。
当brief
运行!help
没有给出参数的命令时,它将给你一个简短的描述。此处显示的机器人的输出:
No Category:
help Shows this message
hi This is where the BRIEF would be found.
Type !help command for more info on a command.
You can also type !help category for more info on a category.
当description
命令作为参数传递给默认帮助命令时,将设置消息,在您的情况下:!help hi
. 机器人的输出将显示为:
This is where the DESCRIPTION is found.
!hi
因此,总而言之,您的新代码将如下所示:
class xkcd(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(brief="This is where the BRIEF would be found.", description="This is where the DESCRIPTION is found.")
async def hi(self, ctx):
await ctx.send('hey')
只需将字符串更改为每个命令所需的字符串。
我还建议阅读有关此问题的文档,可在此处找到。这将遍历 command() 函数的所有参数,并且很高兴知道您拥有的所有选项。
编辑:看到评论澄清了子帮助的意思
推荐阅读
- python - 如何从 Azure Functions 中的存储容器读取多个文件
- jenkins - Jenkins 并行作业 - 如果至少有一个成功(如 successFast)触发另一个作业 - 不要等待所有作业的结果
- javascript - 单击显示和隐藏搜索框
- ruby-on-rails - Sidekiq 对不同的工作使用相同的工作 ID
- wildfly-11 - 在 Wildfly AS 中实现用户锁定功能
- python - 如何使用与上述函数中相同的 Word?如果没有办法做到这一点,我如何在不使用全局变量的情况下使用相同的随机数?
- c# - 如何将 x-ms-blob-type 标头添加到 DataLakeFileSystemClient?
- javascript - 如何将 body.addClass("className") 从父文档应用到 iframe
- kubernetes-helm - 连接来自 configMap 和 secret 的值
- amazon-web-services - 将 aws iam 用户限制到特定区域 (eu-west-1)