Discord.py - 从错误对象获取上下文

Discord.py - Get context from error object

我有一个齿轮test

我有一个功能正在检查命令是否有错误。

在此示例中,此时,如果用户在调用 Discord 中的命令时未提供参数,则会将错误打印到控制台。

我想回复调用带有所述错误消息的命令的原始消息 (!test)。

通常我会使用 commands.Context 来执行此操作,但是在我的实现中它不是参数,最好的方法是什么?

import discord
from discord.ext import commands


class Test(commands.Cog):
    def __init__(self, client):
        self.client = client


    @commands.command()
    async def test(self, ctx, arg1):
        await ctx.reply(arg1)

    @test.error
    async def test_error(self, error):
        if isinstance(error, commands.errors.MissingRequiredArgument):
            # Here I want to reply
            print(error)


def setup(client):
    client.add_cog(Test(client))

提前感谢您的帮助

错误处理程序也将 ctx 作为参数

@test.error
async def test_error(self, ctx, error):
    if isinstance(error, commands.errors.MissingRequiredArgument):
        # Here I want to reply
        print(error)

看看error handling introduction