【发布时间】:2018-12-11 11:29:36
【问题描述】:
您好,我尝试在 await bot.send_message 中添加 {0.subcommand_passed},但出现错误,因此如何添加以捕获在回复中传递的错误命令。
所以如果成员输入?helol 而不是?hello,机器人应该回复helol is a wrong command
@bot.event
async def on_command_error(error, ctx):
if isinstance(error, commands.CommandNotFound):
await bot.send_message(ctx.message.channel, "**Wrong command ** " + ctx.invoked_with)
如果成员在子命令中输入?cool girl 而不是?cool boy,机器人应该回复girl is a wrong sub command
@bot.group(pass_context=True)
async def cool(ctx):
if ctx.invoked_subcommand is None:
if ctx.subcommand_passed:
await bot.say("**Wrong sub command: **{}".format(ctx.subcommand_passed))
else:
await bot.say("**Subcommand required**. {0.author.mention}".format(ctx.message))
@cool.command(pass_context=True)
async def boy(ctx):
msg = "Hello ...".format(ctx.message)
await bot.say(msg)
【问题讨论】:
标签: python python-3.x discord discord.py