- 5 months ago 23
Python Question

Decorator not working correctly

I'm trying to get my decorator working but I keep getting returned with

TypeError: command() takes 1 positional argument but 2 were given

I'm not sure what is happening, is someone able to explain to me what I'm doing wrong?

Decorator Code

def command(command):
def method(self, *args, **kwargs):
return command(self, *args, **kwargs)
return method

Function using Decorator

async def speak(msg : str):
await bot.say(msg)


I would like to have a bot that'll react to commands on a trigger.

For example, I'll send a chat message:

?eval 1 * 2

which the bot will reply with


By using the
, I'll be able to create a flexible system which tells the application that the function is a command on-trigger.


async def eval(self, *args)
await bot.send(eval(*args))


You are decorating with bot.command.

If bot is an object, then bot.command is a method and is called with a self parameter before the command argument, hence the “2 were given”.