python - 获取命令名称
问题描述
我希望机器人获取命令名称,但它给出了错误。我不知道为什么它出错了。请帮我。
错误:未定义的变量“testcommand1”
@commands.command(
name='test'
)
async def testcommand1(self, ctx):
json = {
'_id': ctx.message.id,
'command': str(testcommand1.name),
'guild_id': str(ctx.guild.id),
}
await ctx.send(json)
解决方案
您在 Cog 中使用命令,简单地获取命令,self.testcommand.name
或者您可以从上下文中获取命令,如下所示ctx.command
command = ctx.command
name = command.name
推荐阅读
- kubernetes - 创建多个 Kubernetes 命名空间
- google-cloud-sql - Cloud SQL - 每天都在增长,但不会复制
- python - 'ctrl + c' 不适用于 Windows 上的此 python 代码
- ms-word - 警告:打开了不熟悉的不安全文档
- ios - 快速过滤来自 API 的空值
- python - 如何以编程方式应用多个 where 条件
- angular - Angular + Spring Boot 路由
- xtermjs - xterm.js:如何使用滚动线
- datetime - AWS Athena“无效的日期时间戳”和“文件名路径”
- redis - 多数据中心中的 Redis