def role(*roles: str):
""" Decorator that runs the command only if the author has the specified Roles.
roles must be a string representing a role's name.
NOTE: this function is deprecated. Use the command 'roles' attribute instead.
"""
def decorator(func):
@wraps(func)
async def wrapped(message: discord.Message, *args, **kwargs):
member_roles = [r.name for r in message.author.roles[1:]]
if any(r in member_roles for r in roles):
await func(message, *args, **kwargs)
return wrapped
return decorator
评论列表
文章目录