How to give a command multiple names?

2019-08-27 18:34发布

问题:

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?

回答1:

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)


回答2:

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

Just change the aliases.



回答3:

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)