Id like to create a custom command type i guess you'd call it. the idea is every time the command is called it first checks its custom attribute then modifies that same attribute.
here is the code i have so far, though it doesn't work i hope it demonstrates what im trying to do.
class Perc(commands.Command):
def __init__(self , func , basePrice = 10):
super().__init__(func)
self.basePrice : int = basePrice
async def __call__(self, *args, **kwargs):
# modify base price
self.basePrice = 10
return await super().__call__(*args, **kwargs)
@Perc(basePrice = 25)
async def testPerc(ctx : commands.Context):
await ctx.send("command called")
CodePudding user response:
You need to make the factory function that returns the new class. To decorate a function, you need @decorator(args)
which does (decorator(args))(func)
. This is why __call__
does not work.