python - 不和谐.py | 我可以在命令名中有空格吗?
问题描述
我想问一下我的 discord.py 机器人的命令名称中是否可以有空格,就像命令一样-slowmode off
解决方案
如果您使用的是ext.commands
,那么据我所知,您不能使用其中包含空格的命令名称。但是,您可以拥有:
对于第一种情况,您可以执行以下操作:
@bot.command()
async def slowmode(ctx, arg):
# do something...
await ctx.send('slowmode set to ' + str(arg))
...并使用-slowmode off
or调用它-slowmode hello
。
对于第二种情况:
@bot.group(invoke_without_command=True)
async def slowmode(ctx):
await ctx.send('You must provide a subcommand, for example `-slowmode on` or `-slowmode off`; see `-help` for more')
@slowmode.command(name='on')
async def slowmode_enable(ctx):
# do something...
await ctx.send('slowmode is set to on')
@slowmode.command(name='off')
async def slowmode_disable(ctx):
# do something...
await ctx.send('slowmode is set to off')
...并且调用-slowmode
将显示错误消息,-slowmode on
或者-slowmode off
将运行适当的命令,并-slowmode hello
会导致CommandNotFound
异常。
推荐阅读
- javascript - 如何在下拉列表中添加搜索输入字段?
- python-3.x - 关于groupby的使用
- azure-devops - 我可以在 Azure DevOps 中将我的 Visual Studio Enterprise 许可证用于多个 AAD 帐户吗?
- python - 如何使用 bash 或 Python 将具有多个单页 PDF(蓝图)的文件夹转换为 PNG?
- python - AttributeError:“ca.report”对象没有属性“appliquer”
- angular - 在 ngb-datepicker 中设置日历的开始日期
- django - 我在哪里将我的 Django 根目录放在我的 Linux VPS 中
- laravel - 如何正确处理 Laravel 处理客户订阅已删除事件。?
- webpack - 如何翻译tinymce集成在VUEJS组件中
- c - 相同值的不同 Int 值?