Nubis / Errors
Beheren
Errors
The two kinds of error a Nubis bot meets — mistakes in its definitions, and failures while handling — and what happens to each.
De documentatie van Nubis is in het Engels, net als de API van het framework en zijn meldingen.
Definition errors
Most mistakes a Discord bot can make are in its shape: a name with a capital letter, a description over 100 characters, 26 options, a custom_id that doesn't fit, a sixth row of buttons. Discord rejects these when you register the command or send the message, often far from the code that caused them.
Nubis applies the same rules when a definition is loaded, and throws a NubisError that names what is wrong and where:
NubisError: /mod ban option "days": integer choices must be whole numbers.
NubisError: commands/Config/set: "Config" is not a valid Discord command or option name. Use 1-32 lowercase letters, digits, "-" or "_".
NubisError: nubis.config.ts: "prefix" isn't a config setting. The settings are: root, intents, presence, guards, middleware, onError, autoDeferMs, transport, http, devGuildId.nubis dev prints the error and waits for the next save instead of exiting. Your tests catch them too, since loading a definition is enough to check it.
Handler errors
When a command, component, modal, menu or autocomplete handler throws, Nubis:
- tells the user "Something went wrong. Please try again." — as a reply, an edit or a follow-up, whichever the interaction still allows;
- passes the error to
onError.
Without an onError, Nubis logs it. With one, it's yours:
// nubis.config.ts
import { defineConfig } from "nubis";
export default defineConfig({
onError: (error, info) => {
// info.kind: "command" | "menu" | "component" | "modal" | "autocomplete" | "event"
// info.name: "/config set", a component id, a menu name or an event name
Sentry.captureException(error, { tags: { kind: info.kind, name: info.name } });
},
});Event handlers have no user to tell, so their errors only go to onError.
Messages users see
| When | The user sees |
|---|---|
| A handler throws | Something went wrong. Please try again. |
| A guard denies | The guard's message, privately |
| A component is stale | This no longer works. It may be from an older message; try the command again. |
| A command was removed but Discord still shows it | This command isn't available anymore. Discord may still be catching up. |