0

I have a decorator

class Utilities(commands.Cog):
    def has_any_role(self, *items):
        async def predicate(ctx):
            ctx.command.needed_roles = items
            return await commands.has_any_role(*items).predicate(ctx)
        return commands.check(predicate)

    @has_any_role('Owner', 'Moderator')
    @commands.command()
    async def foo(...):
        ...

However now when I try to access a Commands needed_roles attribute, it'll only return Moderator for foo, since "Owner" is lost in self. How can I fix this without just putting the function outside of the class?

Buster
  • 446
  • 5
  • 16

1 Answers1

1

Try:

@staticmethod
def has_any_role(*items)
...
Glenn Gribble
  • 390
  • 1
  • 7
  • I already tried that, you can't call a staticmethod. same with classmethod – Buster Dec 25 '20 at 17:26
  • 1
    Of course--it is a descriptor-like thing at that point. (You could have mentioned that you tried that in the first place :-). At any rate, this [question](https://stackoverflow.com/questions/1263451/python-decorators-in-classes) answers your question--basically, just leave out self in the method definition. – Glenn Gribble Dec 25 '20 at 18:34