spearkit 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/spearkit/SKILL.md +247 -0
- package/.claude/skills/spearkit/reference/cheatsheet.md +329 -0
- package/AGENTS.md +261 -0
- package/README.md +23 -3
- package/dist/index.cjs +599 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +524 -2
- package/dist/index.d.ts +524 -2
- package/dist/index.js +576 -19
- package/dist/index.js.map +1 -1
- package/docs/README.md +72 -0
- package/docs/api-reference.md +777 -0
- package/docs/auto-defer.md +74 -0
- package/docs/client.md +245 -0
- package/docs/collectors.md +65 -0
- package/docs/commands.md +203 -0
- package/docs/components.md +281 -0
- package/docs/context-menus.md +121 -0
- package/docs/context.md +293 -0
- package/docs/cooldown.md +125 -0
- package/docs/env.md +130 -0
- package/docs/errors.md +73 -0
- package/docs/events.md +152 -0
- package/docs/getting-started.md +147 -0
- package/docs/guards.md +146 -0
- package/docs/loading.md +144 -0
- package/docs/logging.md +195 -0
- package/docs/messages.md +35 -0
- package/docs/migration.md +160 -0
- package/docs/options.md +163 -0
- package/docs/permissions.md +68 -0
- package/docs/plugins.md +116 -0
- package/docs/prefix.md +234 -0
- package/docs/scheduler.md +111 -0
- package/docs/shutdown.md +42 -0
- package/docs/store.md +90 -0
- package/docs/usage.md +188 -0
- package/llms-full.txt +4619 -0
- package/llms.txt +127 -0
- package/package.json +9 -3
package/docs/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# spearkit documentation
|
|
2
|
+
|
|
3
|
+
**discord.js++** — a developer-experience-first layer over discord.js. spearkit
|
|
4
|
+
re-exports all of discord.js (so it's a drop-in replacement) and adds an
|
|
5
|
+
ergonomic, fully type-safe API for events, slash commands and interactive
|
|
6
|
+
components.
|
|
7
|
+
|
|
8
|
+
## Contents
|
|
9
|
+
|
|
10
|
+
1. [Getting started](./getting-started.md) — install, first bot, project layout.
|
|
11
|
+
2. [Client](./client.md) — `SpearClient`, intents, `register`, `start`, deployment.
|
|
12
|
+
3. [Commands](./commands.md) — slash commands, subcommands, permissions, deployment.
|
|
13
|
+
4. [Options](./options.md) — typed option builders, choices, autocomplete.
|
|
14
|
+
5. [Components](./components.md) — buttons, selects, modals, custom-id routing.
|
|
15
|
+
6. [Context menus](./context-menus.md) — user and message "Apps" commands.
|
|
16
|
+
7. [Events](./events.md) — the `event()` helper and the event registry.
|
|
17
|
+
8. [Contexts](./context.md) — reply helpers shared by every handler.
|
|
18
|
+
9. [Guards](./guards.md) — role/permission/owner/guild preconditions.
|
|
19
|
+
10. [Auto-defer](./auto-defer.md) — beat the 3-second `Unknown interaction` error.
|
|
20
|
+
11. [Permissions & hierarchy](./permissions.md) — moderation preflight checks.
|
|
21
|
+
12. [Discord API errors](./errors.md) — recognise and recover from `DiscordAPIError`.
|
|
22
|
+
13. [Cooldowns](./cooldown.md) — per-user/role/guild rate limiting.
|
|
23
|
+
14. [Scheduled tasks](./scheduler.md) — cron and interval jobs.
|
|
24
|
+
15. [Prefix commands](./prefix.md) — classic `!text` commands.
|
|
25
|
+
16. [Collectors](./collectors.md) — await messages, modals and component clicks.
|
|
26
|
+
17. [Key-value store & settings](./store.md) — persist per-guild config + dynamic prefix.
|
|
27
|
+
18. [Messages & limits](./messages.md) — split long output, truncate text.
|
|
28
|
+
19. [Logging](./logging.md) — structured, leveled, scoped logging.
|
|
29
|
+
20. [Usage tracking](./usage.md) — record who used what (store + Discord channel).
|
|
30
|
+
21. [Environment & dotenv](./env.md) — load `.env` and read typed env vars.
|
|
31
|
+
22. [Graceful shutdown](./shutdown.md) — close cleanly on `SIGINT`/`SIGTERM`.
|
|
32
|
+
23. [Plugins](./plugins.md) — bundling features into reusable units.
|
|
33
|
+
24. [File-based loading](./loading.md) — one file per command/event/component.
|
|
34
|
+
25. [Migrating from discord.js](./migration.md) — the drop-in path.
|
|
35
|
+
26. [API reference](./api-reference.md) — every exported symbol.
|
|
36
|
+
|
|
37
|
+
## Why spearkit
|
|
38
|
+
|
|
39
|
+
- **Drop-in.** `import { Client, EmbedBuilder } from "spearkit"` — every discord.js
|
|
40
|
+
export is available, so you can migrate one file at a time.
|
|
41
|
+
- **Fully type-safe.** No `any` or `unknown` leaks into your handlers. Option
|
|
42
|
+
values, custom-id params and modal fields are all inferred from your
|
|
43
|
+
definitions.
|
|
44
|
+
- **Co-located.** A command's options and handler, a button's appearance and
|
|
45
|
+
click logic, a modal's fields and submit logic — each lives in one place.
|
|
46
|
+
- **No boilerplate.** No `interactionCreate` switch statements; spearkit routes
|
|
47
|
+
commands, autocomplete, buttons, selects and modals for you.
|
|
48
|
+
|
|
49
|
+
## Thirty-second tour
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { SpearClient, Intents, command, option, button, row, event } from "spearkit";
|
|
53
|
+
|
|
54
|
+
const client = new SpearClient({ intents: Intents.default });
|
|
55
|
+
|
|
56
|
+
const greet = command({
|
|
57
|
+
name: "greet",
|
|
58
|
+
description: "Greet someone",
|
|
59
|
+
options: { who: option.user({ description: "Who", required: true }) },
|
|
60
|
+
run: (ctx) => ctx.reply(`Hello ${ctx.options.who}!`), // who: User
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const ping = button({
|
|
64
|
+
id: "ping:{n}",
|
|
65
|
+
label: "Ping",
|
|
66
|
+
run: (ctx) => ctx.update(`pong #${ctx.params.n}`), // n: string
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
client.register(greet, ping, event("clientReady", (c) => console.log(c.user.tag)));
|
|
70
|
+
await client.start(process.env.DISCORD_TOKEN);
|
|
71
|
+
await client.deployCommands({ guildId: process.env.GUILD_ID });
|
|
72
|
+
```
|