首页 > 解决方案 > 如何为命令 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> 时,它应该显示有关该命令的更多信息。我怎样才能做到这一点?

标签: pythondiscorddiscord.pybots

解决方案


根据您要显示的内容和要显示的位置,有几个选项,但我会给出重要的选项。briefdescription允许您指定命令的简短描述和完整描述。它们是 的参数,@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() 函数的所有参数,并且很高兴知道您拥有的所有选项。

编辑:看到评论澄清了子帮助的意思


推荐阅读