crousap
crousap

Reputation: 49

How to give a command multiple names?

I have a command:

@bot.command(pass_context=True)
async def hellothere(ctx):
   await Bot.say("Hello {}".format(ctx.message.author))

I want to make a copy of this command that is shorter.

I tried:

@bot.command(pass_context=True)
async def hello(ctx):
   hellothere(ctx)

But I received an error stating that Command is not callable.

Does anyone know how to do this?

Upvotes: 4

Views: 10798

Answers (3)

avib
avib

Reputation: 399

@client.command(pass_context = True , aliases=['purge', 'clean', 'delete'])

Just change the aliases.

Upvotes: 39

Taku
Taku

Reputation: 33714

Here's another more "hacky" way (by making two commands using the same function but with different names, this uses the .callback attribute of Command):

@bot.command(pass_context=True)
async def hellothere(ctx):
    await bot.say("Hello {}".format(ctx.message.author))

bot.command(name="hello", pass_context=True)(hellothere.callback)

Upvotes: 1

Patrick Haugh
Patrick Haugh

Reputation: 60974

You should be able to use the Command.invoke coroutine. Something like

@bot.command(pass_context=True)
async def hello(ctx):
    await hellothere.invoke(ctx)

Upvotes: 2

Related Questions