1

When you declare a command, you know how there are those @commands.has_permissions() things right? I'm trying to make a command that shows the checks for a command, but I'm not sure how to continue. Here is my code so far:

@commands.command(aliases=['sp'])
async def showperms(self, ctx, *, command_name):
    """Shows the permissions needed for a command"""

    com = self.bot.get_command(command_name)
    print(com.checks)

When I do this for a command, I get this output:

[<function bot_has_permissions.<locals>.predicate at 0x7fd64b5ff940>, <function has_permissions.<locals>.predicate at 0x7fd64b5ff550>]

I believe it uses Discord's permission integers, but pretty much no one knows how to use those. I'm not sure how I can 'translate' this into something I can send, such as manage_messages or administrator. The command I used to test has these checks btw:

@commands.has_permissions(manage_channels=True)
@commands.bot_has_permissions(manage_channels=True)

Thanks!!

Jacob Lee
  • 4,405
  • 2
  • 16
  • 37
badpuns
  • 65
  • 1
  • 6

1 Answers1

1

If you check out the discord.py documentation for the Command.checks attribute, you'll see this:

A list of predicates that verifies if the command could be executed with the given Context as the sole parameter.

What is a predicate, you ask? Functional Programming HOWTO: Built-In Functions, A. M. Kuchling:

“A predicate is a function that returns the truth value of some condition.”

So, with the list returned by Command.checks, you can't really do much.

To get each of the checks on your function, you would probably have to iterate through the decorators wrapping the function. I myself don't know how to do that, but you can find a good example of doing so in this Stack Overflow question.

Jacob Lee
  • 4,405
  • 2
  • 16
  • 37