Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Discord 别名的条件语句_Discord_Discord.py_Discord.py Rewrite - Fatal编程技术网

Discord 别名的条件语句

Discord 别名的条件语句,discord,discord.py,discord.py-rewrite,Discord,Discord.py,Discord.py Rewrite,我正在尝试向不同的别名添加变体,而不必重写整个命令: @bot.command(aliases=['test']) async def example(ctx) if alias=='test': #do something first else: #run command 可能的解决方案: 错误是语句的命名。我尝试过使用命令。别名和别名 任何帮助都将不胜感激。ctx.message.content.split(“”)[0].strip(ctx.

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

@bot.command(aliases=['test'])
async def example(ctx)
    if alias=='test':
        #do something first
    else:
        #run command
可能的解决方案:

错误是语句的命名。我尝试过使用
命令。别名
别名

任何帮助都将不胜感激。

ctx.message.content.split(“”)[0].strip(ctx.prefix)
是获取被调用命令的一种非常好的方法,因此您可以执行以下操作

@bot.command(别名=['test'])
异步定义示例(ctx):
命令\u ran=ctx.message.content.split(“”)[0].strip(ctx.prefix)
如果命令_ran==“测试”:
#先做点什么
其他:
#运行命令
这可通过以下方式获得:

触发此调用的命令名。用于查找调用该命令的别名


您可以查看
ctx.message.content
命令是如何调用的,并以此为基础设置条件<代码>如果ctx.message.content.startswith(前缀+“test”)