有没有办法从消息中获取命令的名称(Discord.py)
Is there a way to get the name of the command from the message (Discord.py)
通常当您使用 discord.py 模块创建命令时,您会执行如下操作:
@commands.command(name="my_command", pass_context=True, aliases=["mc"])
def my_command(ctx):
#Do some command action here
我希望能够使用我的 Discord 机器人来管理命令,以便命令只能在指定的频道中使用,例如“my_command”只能用于#general。
获取命令名称的一种简单方法是执行如下操作:
def get_command_name(message, prefix):
command = message.split()[0].strip(prefix)
如果我能用message.command_used
之类的东西来获取命令就更好了,但是我查了文档,好像没有这样的东西。有没有办法从 context
获取命令而不是从字符串操作获取命令?
but I checked the documentation and there doesn't seem to be anything like that
在 commands.Context
的文档中,您也可以找到 command
and invoked_with
, both of which you can use to get the name of the command. In case you want to include possible subcommands, there's invoked_subcommand
。
通常当您使用 discord.py 模块创建命令时,您会执行如下操作:
@commands.command(name="my_command", pass_context=True, aliases=["mc"])
def my_command(ctx):
#Do some command action here
我希望能够使用我的 Discord 机器人来管理命令,以便命令只能在指定的频道中使用,例如“my_command”只能用于#general。
获取命令名称的一种简单方法是执行如下操作:
def get_command_name(message, prefix):
command = message.split()[0].strip(prefix)
如果我能用message.command_used
之类的东西来获取命令就更好了,但是我查了文档,好像没有这样的东西。有没有办法从 context
获取命令而不是从字符串操作获取命令?
but I checked the documentation and there doesn't seem to be anything like that
在 commands.Context
的文档中,您也可以找到 command
and invoked_with
, both of which you can use to get the name of the command. In case you want to include possible subcommands, there's invoked_subcommand
。