How to give a command multiple names?

旧街凉风 提交于 2019-12-13 05:09: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)


来源:https://stackoverflow.com/questions/50204867/how-to-give-a-command-multiple-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!