Я работаю над ботом.Для определенного винтика я хочу создать собственный декоратор проверки, который проверяет, играет ли человек, выполняющий команду, определенную роль.Роль хранится как класс роли в качестве переменной экземпляра.Когда я попытался запустить его, это не сработало.Как ты делаешь декоратор?
class Moderation(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.mod_role = None # Assume there's already a role here
class Decorator:
@classmethod
def requires_mod(cls, func):
async def decorator(self, ctx: commands.Context, *args, **kwargs):
if self.mod_role not in ctx.author.roles:
await ctx.send("You do not have permission to use this command")
func(ctx, *args, **kwargs)
return decorator
@commands.command()
@Decorator.requires_mod
async def purge(self, ctx: commands.Context, amt: int):
await ctx.channel.purge(limit=amt+1)
await ctx.send(f":white_check_mark: | Deleted {amt} messages.")