别名的条件语句

Conditional statements for aliases

我正在尝试为不同的别名添加变体,而不必重写整个命令:

@bot.command(aliases=['test'])
async def example(ctx)
    if alias=='test':
        #do something first
    else:
        #run command

可能的解决方案:

错误是语句的命名。我试过使用 command.aliasesaliases

如有任何帮助,我们将不胜感激。

ctx.message.content.split(' ')[0].strip(ctx.prefix)

是获取调用命令的好方法,因此您可以执行类似

的操作
@bot.command(aliases=['test'])
async def example(ctx):
    command_ran = ctx.message.content.split(' ')[0].strip(ctx.prefix)
    if command_ran == 'test':
        #do something first
    else:
        #run command

这可以作为 ctx.invoked_with

The command name that triggered this invocation. Useful for finding out which alias called the command.