1 回答

TA贡献2003条经验 获得超2个赞
我认为您根本不需要扩展的功能Command。相反,您可以拥有提供您正在寻找的功能的机器人范围on_command_error和 事件。on_command_completion
唯一的问题是返回值。最简单的方法可能是分配一个未使用的属性,ctx而不是尝试捕获返回值(您也可以使用返回值引发自定义错误)
from discord.commands.ext import Bot, BadArgument, MissingRequiredArgument
import sys
bot = Bot("!")
@bot.command()
async def some_command(ctx):
ctx.return_value = 1
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, BadArgument):
await ctx.send("That's a bad argument")
elif isinstance(error, MissingRequiredArgument):
await ctx.send("You're missing an argument")
else:
# This is what the standard on_command_error does
print('Ignoring exception in command {}:'.format(context.command), file=sys.stderr)
traceback.print_exception(type(exception), exception, exception.__traceback__, file=sys.stderr)
@bot.event
async def on_command_completion(ctx):
await ctx.send(str(ctx.return_value))
bot.run("TOKEN")
添加回答
举报