如何解决装饰器参数迷失在自我中
我有一个装饰器
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(...):
...
但是现在当我尝试访问 Command
的 needed_roles
属性时,它只会返回 foo
的主持人,因为 "Owner"
迷失在自我中。如何在不将函数放在类之外的情况下解决这个问题?
解决方法
试试:
@staticmethod
def has_any_role(*items)
...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。