【问题标题】:Is there a way to get the parameters of a command?有没有办法获取命令的参数?
【发布时间】:2021-01-06 13:46:26
【问题描述】:

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

@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}")

【问题讨论】:

    标签: discord.py discord.py-rewrite


    【解决方案1】:

    您需要使用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)
    

    【讨论】:

    • 我试过了,还是不行。是不是因为 description 是只与默认帮助命令一起使用的东西?
    猜你喜欢
    • 2021-04-14
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    • 2021-02-02
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多