python - discord.py 中的多字命令(命令扩展)
问题描述
我正在为我的 Discord 机器人使用 discord.ext.commands 模块,我想要一个名为“setup prefix”的多字命令。
当我使用该命令时,它会抛出一个 CommandNotFound 错误,它表示“setup”不是命令。所以看起来 discord.py 只检查第一个单词。
有没有办法解决这个问题?
这是我的代码片段:
@commands.command(name="setup prefix")
async def set_prefix(self, ctx: Context, prefix: str):
pass
是的,我知道,我可以将“前缀”作为附加参数。但是我必须使用一个功能来完成所有设置命令。
我会很感激你的帮助:)
解决方案
您可能想要使用命令组
@commands.group(invoke_without_subcommand=True)
async def setup(self, ctx, *args):
# general functionality, help, or whatever.
pass
@setup.command()
async def prefix(self, ctx, prefix):
#logic
pass
请查看文档以获取更多信息和示例
另请阅读库常见问题解答,其中包含此用例的一些示例。https://discordpy.readthedocs.io/en/latest/faq.html
注意:请原谅我在手机上的丑陋链接,当我到达电脑时,我会将它们编辑为参考
推荐阅读
- python-3.x - 试图从嵌套列表理解中获取非嵌套列表
- python - 从列表列表中创建一个列表,对 enumerate 方法创建的每个列表使用相同的重复索引号
- r - 我尝试在 R 中读取 tsv 文件,但它会引发有关元素不匹配的错误
- java - 有没有办法从应用程序读取安卓手机上的传入通知?
- html - 如何使我的 html 文本容器更具响应性?
- amazon-web-services - 在 AWS Glue 中,如何将 resolveChoice 应用于 DynamicFrame 中数组内的结构元素?
- javascript - Javascript 没有在 Node.JS API 调用中创建新的函数实例
- node.js - AWS 上的 NodeJS 和反应应用程序部署:不呈现反应 UI
- java - 使用自定义音库将 MIDI 序列写入文件
- applescript - Applescript 发送带有签名的电子邮件