'Discord.py: Can you verify what command check failed in a CheckFailure error?

I was wondering if it is possible to verify which check failed when a CheckError is thrown? I've looked at the documentation and don't see any way to retrieve that information. When a CheckError occurs in my bot the error is too generic and says The check functions for command X failed.

I want to verify which check failed so I can send specific messages to the user based on different check failures.



Solution 1:[1]

Far from the most elegant solution, but if you have custom checks you can throw a CheckError manually if the check is failing. Here's an example:

def is_user_currently_using_command(ongoing_member_commands):
async def predicate(ctx):
    if ctx.author.id in ongoing_member_commands:
        raise commands.CheckFailure("Member has already started a receipt upload.")
    
    return True
    
return commands.check(predicate)

Then when handling CheckErrors you can check the error's arguments for that specific text. It's not great, but it does work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Carla9859