问题描述
最近我一直在尝试使用 discord.py 在 Hy 中编写一个简单的机器人。在 discord.py 中,我们可以编写这样的命令,将最后一个参数转换为包含空格的完整字符串:
@commands.command(description="",help="")
async def say(self,ctx,level,*,remains):
...
但是如果我用 Hy 写成:
#@((commands.command :description "" :help "")
(defn/a say [self ctx level * remains]
...))
它会抱怨缺少必需的参数“文本”。更奇怪的是,Hy官网的defn
部分的示例代码:
(defn compare [a b * keyfn [reverse False]]
(setv result (keyfn a b))
(if (not reverse)
result
(- result)))
甚至在 hy --spy
下都不起作用。是我用错了还是有正确的处理方法?
解决方法
(defn compare…)
对我有用。听起来您运行的 Hy 版本与您正在阅读的文档版本不匹配。