Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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.py主命令作为命令+;参数_Discord.py - Fatal编程技术网

discord.py主命令作为命令+;参数

discord.py主命令作为命令+;参数,discord.py,Discord.py,我有一个这样的主命令: !命令 我需要一个别名函数,该函数使用命令本身作为第一个参数来触发此命令,例如: !别名命令测试将触发!命令别名命令测试 我怎样才能做到这一点?除了命令组之外,我在文档中找不到任何类似的问题或有用的东西,这似乎与我试图实现的目标相反 编辑: 我有一个25个“别名命令”的列表,我想这样做,而不是为这些别名创建25个只调用主函数的函数。因此,寻找一种动态方法来实现这一点,基于字符串数组,您可以在on_message中这样做: cmds=message.content[1:].

我有一个这样的主命令:
!命令

我需要一个别名函数,该函数使用命令本身作为第一个参数来触发此命令,例如:

!别名命令测试将触发
!命令别名命令测试

我怎样才能做到这一点?除了命令组之外,我在文档中找不到任何类似的问题或有用的东西,这似乎与我试图实现的目标相反

编辑:
我有一个25个“别名命令”的列表,我想这样做,而不是为这些别名创建25个只调用主函数的函数。因此,寻找一种动态方法来实现这一点,基于字符串数组

,您可以在
on_message
中这样做:

cmds=message.content[1:].split()
if all(cmd in aliascommands for cmd in cmds):
    msg=message
    msg.content='!command '+msg.content[1:]
    await bot.invoke(await bot.get_context(msg))
这假设
message
discord.message
传递给
on_message
aliascommands
是别名列表,
bot
discord.ext.commands.bot
的实例。此代码做出了很多假设,您可以替换:

1 with the length of your bot's prefix
message with the name of the parameter passed to on_message
aliascommands with the name of the list containing the command aliases
!command with your bot's prefix + the name of the main command
bot with your bot instance