Reputation: 88
I have a cog test
I have a function that is checking to see if there is an error with the command.
In this example, at the moment, if the user does not provide an argument when invoking the command in Discord, the error is printed to the console.
I want to reply to the original message (!test
) that invoked the command with said error message.
Usually I would use commands.Context
to do this, however with it not being a parameter in my implementation what would the best way to about this be?
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))
Thanks in advance for any help
Upvotes: 0
Views: 287
Reputation: 15728
Error handlers also take ctx
as an argument
@test.error
async def test_error(self, ctx, error):
if isinstance(error, commands.errors.MissingRequiredArgument):
# Here I want to reply
print(error)
Take a look at the error handling introduction
Upvotes: 1