【问题标题】:How to use multi-word aliases in discord.py如何在 discord.py 中使用多词别名
【发布时间】:2021-10-21 15:07:00
【问题描述】:
我有一个要使用别名的命令,但别名包含 2 个单词。当我尝试使用别名时,不会触发该命令。有没有办法让我使用多个单词的别名?
命令代码:
@bot.command(aliases=["gn", "night night"]) #
async def goodnight(ctx):
channel = ctx.channel
await channel.send("@everyone Goodnight everyone!")
提前感谢您的帮助!
【问题讨论】:
标签:
python
discord
discord.py
command
【解决方案1】:
您可以通过使用子命令创建命令组来创建带有空格的命令,例如
@bot.group(aliases=["gn", "night"], invoke_without_command=True)
async def goodnight(ctx):
await ctx.send("@everyone Goodnight everyone!")
@goodnight.command()
async def night(ctx):
await ctx.send("@everyone Goodnight everyone!")
有关invoke_without_command here 和下面的cmets 的更多详细信息。
我查看了 discord.py discord 服务器中的讨论,但没有发现其他在命令中包含空格的方法。