有没有办法获取命令的参数?

时间:2021-01-06 01:22:14

标签: discord.py discord.py-rewrite

我想知道是否有办法获取命令的参数以显示如何使用它。我有一个自定义的帮助命令,但我尝试使用与您在装饰器中放置的相同的描述内容。它不起作用(不会给我任何错误或任何东西),但我不知道为什么。

@commands.command()
    async def format(self, ctx, command):
        formatting = discord.Embed(title=f"Formatting for .{command}", description=command.description)
        formatting.set_thumbnail(url=self.bot.avatar_url)
        formatting.set_footer(text=f"Requested by {ctx.author.mention}", icon_url=ctx.author.avatar_url)

        ctx.send(embed=formatting)

这是我的命令之一,其中包含描述内容:

"""Change Nickname command"""
    @commands.command(aliases=['chnick'], description="Usage: .nick [member mention] [nickname to change to]")
    @commands.has_permissions(manage_channels=True)
    async def change_nick(self, ctx, member: discord.Member, nick):
        """Changes a user's nickname\nAliases: chnick"""

        await member.edit(nick=nick)
        await ctx.send(f"Nickname was changed for {member.mention}")

1 个答案:

答案 0 :(得分:0)

您需要使用 get_command()

获取命令
@commands.command()
async def format(self, ctx, command):
    command = self.bot.get_command(command)
    formatting = discord.Embed(title=f"Formatting for .{command.name}", description=command.description)
    formatting.set_thumbnail(url=self.bot.avatar_url)
    formatting.set_footer(text=f"Requested by {ctx.author.mention}", icon_url=ctx.author.avatar_url)
    await ctx.send(embed=formatting)