spearkit
Guides

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);

Or let the context do it: await ctx.sendLong(hugeLog).

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…"

Polls

poll() returns an ordinary discord.js PollData payload, with readable option names and validation for Discord's limits:

import { poll } from "spearkit";

await ctx.reply({
  poll: poll({
    question: "Ship it?",
    answers: [{ text: "Yes", emoji: "✅" }, "Not yet"],
    durationHours: 6, // 1–768; default 24
    multiselect: false,
  }),
});

Questions allow 300 characters, answers 55 characters, and polls accept 2–10 answers. Poll messages cannot be edited after creation. End one early with message.poll?.end() and fetch answer voters with message.poll?.answers.get(id)?.fetchVoters().

Polls cannot be combined with Components V2 (MessageFlags.IsComponentsV2). Discord apps can create and inspect polls, but cannot vote in them.

Sources: Discord Poll Resource and discord.js PollData.

On this page