Skip to content

GramIO API Reference / gramio/dist / Hooks / OnError

Type Alias: OnError()<T, Ctx>

OnError<T, Ctx> = (options) => unknown

Defined in: gramio/index.d.ts:714

Type for onError hook

Type Parameters

Type ParameterDefault type
T extends ErrorDefinitions-
Ctx extends Context<any>Context<AnyBot>

Parameters

ParameterType
optionsOnErrorContext<Ctx, T>

Returns

unknown

Example

typescript
bot.on("message", () => {
    bot.api.sendMessage({
        chat_id: "@not_found",
        text: "Chat not exists....",
    });
});

bot.onError(({ context, kind, error }) => {
    if (context.is("message")) return context.send(`${kind}: ${error.message}`);
});

Documentation