Skip to content

Errors

catch_autocomplete #

catch_autocomplete(
    *exceptions: type[Exception],
) -> Callable[
    [AutocompleteErrorHandlerCallbackT[Any]],
    Includable[AutocompleteErrorHandlerCallbackT[Any]],
]

Catch an exception or subclasses of an exception passed into this function when the exception is raised in an autocomplete handler.

Example#
@client.include
@crescent.catch_autocomplete(Exception)
async def on_autocomplete_random_error(
    exc: Exception,
    ctx: crescent.AutocompleteContext,
    inter: hikari.AutocompleteInteractionOption,
) -> None:
    print(f"{exc} raised in autocomplete for {ctx.command}!")

# An autocomplete callback that a command is using.
async def example_autocomplete(
    ctx: crescent.AutocompleteContext, option: hikari.AutocompleteInteractionOption
) -> list[tuple[str, str]]:
    raise Exception

catch_command #

catch_command(
    *exceptions: type[Exception],
) -> Callable[
    [CommandErrorHandlerCallbackT[Any]],
    Includable[CommandErrorHandlerCallbackT[Any]],
]

Catch an exception or subclasses of an exception passed into this function when the exception is raised in a command.

Example#
@client.include
@crescent.catch_command(Exception)
async def handler(exc: Exception, ctx: crescent.Context) -> None:
    await ctx.respond(f"{exc} raised in {ctx.command}!")

@client.include
@crescent.command
async def example_command(ctx: crescent.Context):
    ...

catch_event #

catch_event(
    *exceptions: type[Exception],
) -> Callable[
    [EventErrorHandlerCallbackT[Any]],
    Includable[EventErrorHandlerCallbackT[Any]],
]

Catch an exception or subclasses of an exception passed into this function when the exception is raised in an event.

Example#
@client.include
@crescent.catch_event(Exception)
async def handler(exc: Exception, event: hikari.Event) -> None:
    print(f"{exc} raised in {event}!")

@client.include
@crescent.event
async def example_error(event: hikari.MessageCreateEvent) -> None:
    raise Exception