Messages & limits
Discord caps a message's content at 2000 characters. Long output — a log dump, a list, an AI response — silently fails or throws unless you split it. spearkit ships two helpers…
Split long output
chunkMessage(text, options?) breaks text into chunks that each fit the limit,
preferring line boundaries (and word boundaries for an over-long single line) so
you never lose the tail:
import { chunkMessage } from "spearkit";
const parts = chunkMessage(hugeLog); // default max = 2000
await ctx.reply(parts[0] ?? "(empty)");
for (const part of parts.slice(1)) await ctx.followUp(part);Pass { max } to target a smaller budget (e.g. inside a code block or embed
description). MESSAGE_CHARACTER_LIMIT (2000) is exported as the default.
Truncate
truncate(text, max, suffix?) cuts text to max characters, appending the
suffix (default …) — the result, suffix included, never exceeds max:
import { truncate } from "spearkit";
embed.setFooter({ text: truncate(reason, 100) });
truncate("a very long reason", 10); // → "a very lo…"Discord API errors
discord.js reports REST failures as DiscordAPIError with a numeric code (10008 "Unknown Message", 50013 "Missing Permissions", 50007 "Cannot send DMs to this user", …). Catching…
Usage tracking
Usage tracking records who used what: every command, component, context-menu and prefix-command invocation — successful or errored — becomes a UsageEvent that spearkit can persist…