How to get the arguments of a decorator function?

Question:

I have a command with a decorator @commands.has_role("admin") and I need to get that role. This is what I have tried:

filtered = await self.filter_commands(self.context.bot.commands, sort=True) 
checks = [command.checks for command in filtered]
for check in checks:
  for c in check:
    print(c.role) 

but returns AttributeError: 'function' object has no attribute 'role'.
How do I get the value of that decorator? This decorator is not custom, it is part of discord.py(discord.ext.commands)

Asked By: Vlone

||

Answers:

Sometimes necessary values are stored in attributes of the wrapper. Not for the discord wrapper.

Decorators make use of closures. To find their closed values use

function.__closure__[0].cell_contents

function here is c

Answered By: Daraan