mini-interactions 0.0.0-stage → 0.15.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/LICENSE +21 -0
- package/MIGRATION.md +126 -0
- package/README.md +253 -2
- package/dist/bot.d.ts +58 -0
- package/dist/bot.js +217 -0
- package/dist/builders/ActionRowBuilder.d.ts +22 -0
- package/dist/builders/ActionRowBuilder.js +33 -0
- package/dist/builders/AutomodRuleBuilder.d.ts +45 -0
- package/dist/builders/AutomodRuleBuilder.js +151 -0
- package/dist/builders/ButtonBuilder.d.ts +53 -0
- package/dist/builders/ButtonBuilder.js +124 -0
- package/dist/builders/ChannelSelectMenuBuilder.d.ts +53 -0
- package/dist/builders/ChannelSelectMenuBuilder.js +105 -0
- package/dist/builders/CheckboxBuilder.d.ts +20 -0
- package/dist/builders/CheckboxBuilder.js +20 -0
- package/dist/builders/CheckboxGroupBuilder.d.ts +25 -0
- package/dist/builders/CheckboxGroupBuilder.js +48 -0
- package/dist/builders/EmbedBuilder.d.ts +33 -0
- package/dist/builders/EmbedBuilder.js +103 -0
- package/dist/builders/FileUploadBuilder.d.ts +17 -0
- package/dist/builders/FileUploadBuilder.js +22 -0
- package/dist/builders/LabelBuilder.d.ts +16 -0
- package/dist/builders/LabelBuilder.js +21 -0
- package/dist/builders/MiniContainerBuilder.d.ts +131 -0
- package/dist/builders/MiniContainerBuilder.js +347 -0
- package/dist/builders/ModalBuilder.d.ts +16 -0
- package/dist/builders/ModalBuilder.js +36 -0
- package/dist/builders/ModalChannelSelectMenuBuilder.d.ts +29 -0
- package/dist/builders/ModalChannelSelectMenuBuilder.js +25 -0
- package/dist/builders/ModalMentionableSelectMenuBuilder.d.ts +53 -0
- package/dist/builders/ModalMentionableSelectMenuBuilder.js +87 -0
- package/dist/builders/ModalRoleSelectMenuBuilder.d.ts +27 -0
- package/dist/builders/ModalRoleSelectMenuBuilder.js +24 -0
- package/dist/builders/ModalStringSelectMenuBuilder.d.ts +62 -0
- package/dist/builders/ModalStringSelectMenuBuilder.js +120 -0
- package/dist/builders/ModalUserSelectMenuBuilder.d.ts +53 -0
- package/dist/builders/ModalUserSelectMenuBuilder.js +96 -0
- package/dist/builders/RadioBuilder.d.ts +22 -0
- package/dist/builders/RadioBuilder.js +36 -0
- package/dist/builders/RoleSelectMenuBuilder.d.ts +47 -0
- package/dist/builders/RoleSelectMenuBuilder.js +92 -0
- package/dist/builders/StringSelectMenuBuilder.d.ts +52 -0
- package/dist/builders/StringSelectMenuBuilder.js +104 -0
- package/dist/builders/StringSelectMenuOptionBuilder.d.ts +46 -0
- package/dist/builders/StringSelectMenuOptionBuilder.js +106 -0
- package/dist/builders/TextInputBuilder.d.ts +23 -0
- package/dist/builders/TextInputBuilder.js +26 -0
- package/dist/builders/index.d.ts +44 -0
- package/dist/builders/index.js +22 -0
- package/dist/builders/shared.d.ts +8 -0
- package/dist/builders/shared.js +11 -0
- package/dist/commands/CommandBuilder.d.ts +278 -0
- package/dist/commands/CommandBuilder.js +687 -0
- package/dist/commands/ContextMenuCommandBuilder.d.ts +94 -0
- package/dist/commands/ContextMenuCommandBuilder.js +145 -0
- package/dist/core/http/DiscordRestClient.d.ts +400 -0
- package/dist/core/http/DiscordRestClient.js +988 -0
- package/dist/core/interactions/InteractionContext.d.ts +33 -0
- package/dist/core/interactions/InteractionContext.js +61 -0
- package/dist/core/interactions/InteractionVerifier.d.ts +8 -0
- package/dist/core/interactions/InteractionVerifier.js +9 -0
- package/dist/core/messages/DiscordSentMessage.d.ts +32 -0
- package/dist/core/messages/DiscordSentMessage.js +64 -0
- package/dist/core/messages/message-payloads.d.ts +94 -0
- package/dist/core/messages/message-payloads.js +99 -0
- package/dist/core/webhooks/DiscordWebhook.d.ts +14 -0
- package/dist/core/webhooks/DiscordWebhook.js +69 -0
- package/dist/database/MiniDataBuilder.d.ts +61 -0
- package/dist/database/MiniDataBuilder.js +98 -0
- package/dist/database/MiniDatabase.d.ts +67 -0
- package/dist/database/MiniDatabase.js +222 -0
- package/dist/database/MiniDatabaseBuilder.d.ts +58 -0
- package/dist/database/MiniDatabaseBuilder.js +84 -0
- package/dist/database/index.d.ts +5 -0
- package/dist/database/index.js +3 -0
- package/dist/identity/ApplicationIdentityProfile.d.ts +188 -0
- package/dist/identity/ApplicationIdentityProfile.js +207 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +34 -0
- package/dist/lobby/Lobby.d.ts +150 -0
- package/dist/lobby/Lobby.js +90 -0
- package/dist/node/MiniInteraction.d.ts +199 -0
- package/dist/node/MiniInteraction.js +861 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +1 -0
- package/dist/oauth2/DiscordOAuth.d.ts +49 -0
- package/dist/oauth2/DiscordOAuth.js +113 -0
- package/dist/oauth2/OAuth2Builder.d.ts +296 -0
- package/dist/oauth2/OAuth2Builder.js +435 -0
- package/dist/oauth2/OAuth2Scopes.d.ts +285 -0
- package/dist/oauth2/OAuth2Scopes.js +438 -0
- package/dist/oauth2/OAuthTokenStorage.d.ts +37 -0
- package/dist/oauth2/OAuthTokenStorage.js +109 -0
- package/dist/oauth2/index.d.ts +8 -0
- package/dist/oauth2/index.js +4 -0
- package/dist/router/AutocompleteContext.d.ts +36 -0
- package/dist/router/AutocompleteContext.js +82 -0
- package/dist/router/InteractionRouter.d.ts +82 -0
- package/dist/router/InteractionRouter.js +225 -0
- package/dist/types/ButtonStyle.d.ts +16 -0
- package/dist/types/ButtonStyle.js +17 -0
- package/dist/types/ChannelType.d.ts +2 -0
- package/dist/types/ChannelType.js +2 -0
- package/dist/types/Commands.d.ts +35 -0
- package/dist/types/Commands.js +1 -0
- package/dist/types/ComponentTypes.d.ts +19 -0
- package/dist/types/ComponentTypes.js +1 -0
- package/dist/types/InteractionFlags.d.ts +5 -0
- package/dist/types/InteractionFlags.js +6 -0
- package/dist/types/PermissionFlags.d.ts +56 -0
- package/dist/types/PermissionFlags.js +5 -0
- package/dist/types/RoleConnectionMetadata.d.ts +14 -0
- package/dist/types/RoleConnectionMetadata.js +1 -0
- package/dist/types/RoleConnectionMetadataTypes.d.ts +11 -0
- package/dist/types/RoleConnectionMetadataTypes.js +12 -0
- package/dist/types/SeparatorSpacingSize.d.ts +2 -0
- package/dist/types/SeparatorSpacingSize.js +2 -0
- package/dist/types/checkbox.d.ts +16 -0
- package/dist/types/checkbox.js +12 -0
- package/dist/types/discord.d.ts +2 -0
- package/dist/types/discord.js +1 -0
- package/dist/types/radio.d.ts +12 -0
- package/dist/types/radio.js +10 -0
- package/dist/types/validation.d.ts +14 -0
- package/dist/types/validation.js +40 -0
- package/dist/utils/CommandInteractionOptions.d.ts +66 -0
- package/dist/utils/CommandInteractionOptions.js +364 -0
- package/dist/utils/ContextMenuInteraction.d.ts +76 -0
- package/dist/utils/ContextMenuInteraction.js +152 -0
- package/dist/utils/MessageComponentInteraction.d.ts +148 -0
- package/dist/utils/MessageComponentInteraction.js +259 -0
- package/dist/utils/ModalSubmitInteraction.d.ts +86 -0
- package/dist/utils/ModalSubmitInteraction.js +267 -0
- package/dist/utils/cdn.d.ts +30 -0
- package/dist/utils/cdn.js +60 -0
- package/dist/utils/formatting.d.ts +76 -0
- package/dist/utils/formatting.js +132 -0
- package/dist/utils/interactionMessageHelpers.d.ts +40 -0
- package/dist/utils/interactionMessageHelpers.js +118 -0
- package/dist/utils/localization.d.ts +25 -0
- package/dist/utils/localization.js +38 -0
- package/dist/utils/snowflake.d.ts +19 -0
- package/dist/utils/snowflake.js +32 -0
- package/dist/webhooks/WebhookEvent.d.ts +229 -0
- package/dist/webhooks/WebhookEvent.js +59 -0
- package/dist/webhooks/WebhookEventRouter.d.ts +123 -0
- package/dist/webhooks/WebhookEventRouter.js +160 -0
- package/dist/webhooks/WebhookEventVerifier.d.ts +33 -0
- package/dist/webhooks/WebhookEventVerifier.js +37 -0
- package/dist/webhooks/index.d.ts +6 -0
- package/dist/webhooks/index.js +3 -0
- package/package.json +90 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Minesa™
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/MIGRATION.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Migration Guide
|
|
2
|
+
|
|
3
|
+
## v0.15 module split and rename
|
|
4
|
+
|
|
5
|
+
The package previously published as `@minesa-org/mini-interaction` is now the unscoped `mini-interactions` package. Optional features are still modular, but they are consumed as subpath exports from one install:
|
|
6
|
+
|
|
7
|
+
| Old feature | New import |
|
|
8
|
+
|---|---|
|
|
9
|
+
| Core/router/builders/REST | `mini-interactions` |
|
|
10
|
+
| `MiniDatabase`, `MiniDataBuilder`, `MiniDatabaseBuilder` | `mini-interactions/database` |
|
|
11
|
+
| OAuth helpers, `OAuth2Builder`, `OAuthTokenStorage` | `mini-interactions/oauth2` |
|
|
12
|
+
| Webhook event router/endpoint/verifier | `mini-interactions/webhooks` |
|
|
13
|
+
| `MiniInteraction` / `LegacyMiniInteractionAdapter` | `mini-interactions/node` |
|
|
14
|
+
|
|
15
|
+
The fastest migration is usually to replace manual endpoint plumbing with `createBot`:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createBot } from "mini-interactions";
|
|
19
|
+
|
|
20
|
+
const bot = createBot();
|
|
21
|
+
|
|
22
|
+
bot.command("ping", (interaction) =>
|
|
23
|
+
interaction.reply({ content: "Pong!" }),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export const POST = bot.fetch;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`createBot` resolves `DISCORD_PUBLIC_KEY`, `DISCORD_APPLICATION_ID`, `DISCORD_BOT_TOKEN`, and `DISCORD_GUILD_ID` from explicit options, a runtime environment argument, or `process.env` when available. Use builder overloads plus `bot.syncCommands()` when you want the bot to own command registration.
|
|
30
|
+
|
|
31
|
+
The repository now uses Bun for dependency management, tests, and build orchestration: `bun install`, `bun test`, and `bun run build`. The published runtime still works on Node 20+; only `mini-interactions/node` requires the optional `@vercel/functions` peer, and only `mini-interactions/database` requires the optional `mongodb` peer.
|
|
32
|
+
|
|
33
|
+
Interaction wrapper names were already type-only concepts; import them with `import type` when using `verbatimModuleSyntax`.
|
|
34
|
+
|
|
35
|
+
## From legacy `MiniInteraction` to the core/router stack
|
|
36
|
+
|
|
37
|
+
The legacy `MiniInteraction` class (still exported as
|
|
38
|
+
`LegacyMiniInteractionAdapter`) keeps working for backwards compatibility.
|
|
39
|
+
New code should use the modular stack:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// Before (legacy, all-in-one)
|
|
43
|
+
const mini = new MiniInteraction({ commandsDirectory: "commands" });
|
|
44
|
+
export default mini.createNodeHandler();
|
|
45
|
+
|
|
46
|
+
// After (modular)
|
|
47
|
+
import {
|
|
48
|
+
DiscordRestClient,
|
|
49
|
+
InteractionContext,
|
|
50
|
+
InteractionRouter,
|
|
51
|
+
verifyAndParseInteraction,
|
|
52
|
+
} from "mini-interactions";
|
|
53
|
+
|
|
54
|
+
const rest = new DiscordRestClient({
|
|
55
|
+
applicationId: process.env.DISCORD_APPLICATION_ID,
|
|
56
|
+
token: process.env.DISCORD_BOT_TOKEN,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const router = new InteractionRouter({ rest })
|
|
60
|
+
.onCommand("ping", async (interaction, ctx) => ctx.reply({ content: "Pong!" }))
|
|
61
|
+
.onComponent("my_button", async (interaction, ctx) => ctx.reply({ content: "Clicked!" }))
|
|
62
|
+
.onModal("my_modal", async (interaction, ctx) => ctx.reply({ content: "Submitted!" }));
|
|
63
|
+
|
|
64
|
+
export async function POST(req: Request) {
|
|
65
|
+
const interaction = await verifyAndParseInteraction({ /* ... */ });
|
|
66
|
+
if (interaction.type === 1) return Response.json({ type: 1 });
|
|
67
|
+
|
|
68
|
+
const ctx = new InteractionContext({ interaction, rest });
|
|
69
|
+
const response = await router.dispatch(interaction, ctx);
|
|
70
|
+
return Response.json(response ?? ctx.deferReply());
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Key differences
|
|
75
|
+
|
|
76
|
+
| Legacy | Modular |
|
|
77
|
+
|---|---|
|
|
78
|
+
| File-system auto-discovery of `commands/` / `components/` directories | Explicit `router.onCommand/onComponent/onModal` registrations |
|
|
79
|
+
| Handlers receive loosely typed wrappers | Handlers receive fully typed wrapped interactions + `InteractionContext` |
|
|
80
|
+
| Modal detection by file naming (`*.modal.ts`) | Explicit `onModal` registration |
|
|
81
|
+
|
|
82
|
+
## v0.5 breaking changes
|
|
83
|
+
|
|
84
|
+
### Radio & checkbox components
|
|
85
|
+
|
|
86
|
+
The invented component types were replaced by Discord's real modal components:
|
|
87
|
+
|
|
88
|
+
- `RADIO_COMPONENT_TYPE` is now **21** (`RadioGroup`), not `2001`.
|
|
89
|
+
- `CheckboxBuilder` now builds a **single checkbox** (type 23): only
|
|
90
|
+
`setCustomId()` and `setDefault()`.
|
|
91
|
+
- The former options-array checkbox moved to the new **`CheckboxGroupBuilder`**
|
|
92
|
+
(type 22): options must be 2–10 and support `minValues`/`maxValues`.
|
|
93
|
+
- `RadioBuilder` enforces Discord's 2–10 option limit; `setDisabled()` was
|
|
94
|
+
removed (not valid on modal radio groups); option emoji was dropped per spec.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
// Before (invalid payload, rejected by Discord)
|
|
98
|
+
new CheckboxBuilder().addOptions({ label: "A", value: "a" });
|
|
99
|
+
|
|
100
|
+
// After — single checkbox
|
|
101
|
+
new CheckboxBuilder().setCustomId("tos").setDefault(false);
|
|
102
|
+
|
|
103
|
+
// After — multi-option group
|
|
104
|
+
new CheckboxGroupBuilder().setCustomId("prefs")
|
|
105
|
+
.addOptions({ label: "Email", value: "email" }, { label: "Push", value: "push" });
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Modal select menus
|
|
109
|
+
|
|
110
|
+
- `disabled` is no longer serialised (Discord rejects it on modal selects);
|
|
111
|
+
`setDisabled()` remains but is deprecated and ignored.
|
|
112
|
+
- `placeholder` is validated against the 150-character limit.
|
|
113
|
+
|
|
114
|
+
### Components V2
|
|
115
|
+
|
|
116
|
+
- Sending a Components V2 message together with `content`, `embeds` or
|
|
117
|
+
`sticker_ids` now throws — use TextDisplay components instead.
|
|
118
|
+
- `ModalBuilder` accepts top-level TextDisplay alongside ActionRow and Label.
|
|
119
|
+
|
|
120
|
+
## v0.6 router changes
|
|
121
|
+
|
|
122
|
+
- `InteractionRouter` handlers now receive **wrapped interactions** (option
|
|
123
|
+
resolver, reply helpers) instead of raw API payloads.
|
|
124
|
+
- Context menus and Primary Entry Point commands are dispatched via
|
|
125
|
+
`onUserCommand`, `onMessageCommand` and `onEntryPointCommand`.
|
|
126
|
+
- Autocomplete is handled via `onAutocomplete` with an `AutocompleteContext`.
|
package/README.md
CHANGED
|
@@ -1,3 +1,254 @@
|
|
|
1
|
-
#
|
|
1
|
+
# mini-interactions
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Edge-first, type-safe Discord interactions for modern TypeScript bots.**
|
|
4
|
+
|
|
5
|
+
`mini-interactions` is one install with focused subpath modules: bot creation, signature verification, command routing, components, modals, autocomplete, builders, and Discord REST helpers stay in the edge-safe core, while optional features load only when imported.
|
|
6
|
+
|
|
7
|
+
| Import path | Use it for |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `mini-interactions` | Discord interactions, bot runtime, builders, REST, lobbies, identity profiles |
|
|
10
|
+
| `mini-interactions/database` | Optional MongoDB-backed document storage |
|
|
11
|
+
| `mini-interactions/oauth2` | Discord OAuth2 URLs, token exchange, refresh, revocation, typed scopes |
|
|
12
|
+
| `mini-interactions/webhooks` | Signature-verified Discord webhook event endpoints |
|
|
13
|
+
| `mini-interactions/node` | Legacy Node/Vercel filesystem adapter (`MiniInteraction`) |
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add mini-interactions
|
|
19
|
+
# npm install mini-interactions also works; the runtime only needs Node 20+ or Bun 1.2+
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Optional integration dependencies are installed only when their module is used:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
bun add mongodb # only for mini-interactions/database
|
|
26
|
+
bun add @vercel/functions # only for the legacy mini-interactions/node adapter
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## A production-shaped bot in one file
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { CommandBuilder, createBot } from "mini-interactions";
|
|
33
|
+
|
|
34
|
+
const bot = createBot({
|
|
35
|
+
publicKey: process.env.DISCORD_PUBLIC_KEY!,
|
|
36
|
+
applicationId: process.env.DISCORD_APPLICATION_ID!,
|
|
37
|
+
token: process.env.DISCORD_BOT_TOKEN!,
|
|
38
|
+
// Use a guild in development for instant command propagation.
|
|
39
|
+
guildId: process.env.DISCORD_GUILD_ID,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
bot.command(
|
|
43
|
+
new CommandBuilder()
|
|
44
|
+
.setName("ping")
|
|
45
|
+
.setDescription("Check whether the bot is alive"),
|
|
46
|
+
(interaction) => interaction.reply({ content: "Pong!" }),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
bot.component("ping:again", (interaction) =>
|
|
50
|
+
interaction.reply({ content: "Still pong!", ephemeral: true }),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// Next.js / Vercel route handlers:
|
|
54
|
+
export const POST = bot.fetch;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Register builder-defined commands once during deployment — not on every request:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// scripts/sync-commands.ts
|
|
61
|
+
import { bot } from "../src/bot.js";
|
|
62
|
+
|
|
63
|
+
await bot.syncCommands();
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`syncCommands()` uses Discord's bulk overwrite endpoint for the configured global or guild scope. Guild registration is recommended while developing because global commands can take time to propagate.
|
|
67
|
+
|
|
68
|
+
## Cloudflare Workers
|
|
69
|
+
|
|
70
|
+
The core runtime is edge-safe. Credentials can come from the Worker environment at request time:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { CommandBuilder, createBot } from "mini-interactions";
|
|
74
|
+
|
|
75
|
+
const bot = createBot();
|
|
76
|
+
|
|
77
|
+
bot.command(
|
|
78
|
+
new CommandBuilder().setName("ping").setDescription("Ping"),
|
|
79
|
+
(interaction) => interaction.reply({ content: "Pong!" }),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
export default {
|
|
83
|
+
fetch(request: Request, env: Record<string, string>) {
|
|
84
|
+
return bot.fetch(request, env);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Set `DISCORD_PUBLIC_KEY`, `DISCORD_APPLICATION_ID`, and `DISCORD_BOT_TOKEN` as Worker secrets/variables.
|
|
90
|
+
|
|
91
|
+
## Commands, components, modals, autocomplete
|
|
92
|
+
|
|
93
|
+
The simple methods delegate to the typed router:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
bot.command("echo", (interaction) => {
|
|
97
|
+
const text = interaction.options.getString("text", true);
|
|
98
|
+
return interaction.reply({ content: text });
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
bot.userCommand("Inspect User", (interaction) =>
|
|
102
|
+
interaction.reply({ content: `User: ${interaction.targetUser?.username ?? interaction.data.target_id}` }),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
bot.modal("feedback", (interaction) => {
|
|
106
|
+
const feedback = interaction.getTextFieldValue("feedback_text");
|
|
107
|
+
return interaction.reply({ content: `Thanks: ${feedback}`, ephemeral: true });
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
bot.autocomplete("search", async (autocomplete) => {
|
|
111
|
+
const focused = autocomplete.getFocusedOption();
|
|
112
|
+
return autocomplete.respond([
|
|
113
|
+
{ name: `Result for ${focused?.value ?? ""}`, value: "result" },
|
|
114
|
+
]);
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Handlers receive typed interaction wrappers with `reply`, `deferReply`, `editReply`, `followUp`, and `showModal` helpers. Slow operations should call `deferReply()` explicitly; Discord requires the initial interaction response within three seconds.
|
|
119
|
+
|
|
120
|
+
## Components and message builders
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "mini-interactions";
|
|
124
|
+
|
|
125
|
+
const row = new ActionRowBuilder().addComponents(
|
|
126
|
+
new ButtonBuilder()
|
|
127
|
+
.setCustomId("ping:again")
|
|
128
|
+
.setLabel("Again")
|
|
129
|
+
.setStyle(ButtonStyle.Primary),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
bot.command("ping", (interaction) =>
|
|
133
|
+
interaction.reply({ content: "Pong!", components: [row] }),
|
|
134
|
+
);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Builders validate Discord constraints while typing payloads precisely. Components V2 payloads cannot be mixed with legacy `content`, `embeds`, or sticker IDs; the package rejects those combinations before Discord does.
|
|
138
|
+
|
|
139
|
+
## Database module
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
bun add mongodb
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { MiniDatabase, MiniDataBuilder } from "mini-interactions/database";
|
|
147
|
+
|
|
148
|
+
const userSchema = new MiniDataBuilder()
|
|
149
|
+
.addField("userId", "string", { required: true })
|
|
150
|
+
.addField("coins", "number", { default: 0 });
|
|
151
|
+
|
|
152
|
+
const db = MiniDatabase.fromEnv(userSchema);
|
|
153
|
+
|
|
154
|
+
await db.set("user-1", { userId: "user-1", coins: 10 });
|
|
155
|
+
const user = await db.get("user-1");
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
The database module has an optional `mongodb` peer dependency. The core interaction runtime never imports MongoDB.
|
|
159
|
+
|
|
160
|
+
## OAuth2 module
|
|
161
|
+
|
|
162
|
+
OAuth2 is included in the same package and loaded through its subpath:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import {
|
|
166
|
+
OAuth2Builder,
|
|
167
|
+
OAuth2ScopePresets,
|
|
168
|
+
} from "mini-interactions/oauth2";
|
|
169
|
+
|
|
170
|
+
const oauth = new OAuth2Builder({
|
|
171
|
+
clientId: process.env.DISCORD_CLIENT_ID!,
|
|
172
|
+
clientSecret: process.env.DISCORD_CLIENT_SECRET!,
|
|
173
|
+
redirectUri: "https://example.com/discord/callback",
|
|
174
|
+
}).addScopes(...OAuth2ScopePresets.SignIn);
|
|
175
|
+
|
|
176
|
+
const { url, state } = oauth.build();
|
|
177
|
+
// Redirect the user to `url` and persist `state` for CSRF validation.
|
|
178
|
+
|
|
179
|
+
const tokens = await oauth.exchangeCode(code);
|
|
180
|
+
const authorization = await oauth.getAuthorizationInfo(tokens.access_token);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The scope registry is typed and documented. Invalid combinations are rejected locally with machine-readable errors instead of failing after a user-facing redirect.
|
|
184
|
+
|
|
185
|
+
## Webhook events module
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import {
|
|
189
|
+
WebhookEventEndpoint,
|
|
190
|
+
WebhookEventRouter,
|
|
191
|
+
WebhookEventType,
|
|
192
|
+
} from "mini-interactions/webhooks";
|
|
193
|
+
|
|
194
|
+
const router = new WebhookEventRouter()
|
|
195
|
+
.on(WebhookEventType.ApplicationAuthorized, (payload) => {
|
|
196
|
+
console.log("authorized", payload.event.data?.user.id);
|
|
197
|
+
})
|
|
198
|
+
.on(WebhookEventType.ApplicationDeauthorized, async (payload) => {
|
|
199
|
+
await unlinkAccount(payload.event.data!.user.id);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const endpoint = new WebhookEventEndpoint({
|
|
203
|
+
publicKey: process.env.DISCORD_PUBLIC_KEY!,
|
|
204
|
+
router,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
export const POST = (request: Request) => endpoint.handleFetch(request);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Webhook events are signed, retried, unordered, and not realtime. Keep handlers idempotent and heavy work behind `waitUntil` where your platform supports it.
|
|
211
|
+
|
|
212
|
+
## Legacy Node/Vercel adapter
|
|
213
|
+
|
|
214
|
+
Existing filesystem-discovery bots can use the compatibility adapter without forcing Node/Vercel dependencies into the edge-safe core:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
bun add @vercel/functions
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
import { MiniInteraction } from "mini-interactions/node";
|
|
222
|
+
|
|
223
|
+
const mini = new MiniInteraction({
|
|
224
|
+
commandsDirectory: "commands",
|
|
225
|
+
componentsDirectory: "components",
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
export default mini.createNodeHandler();
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
New projects should prefer `createBot` from `mini-interactions`.
|
|
232
|
+
|
|
233
|
+
## Architecture
|
|
234
|
+
|
|
235
|
+
```text
|
|
236
|
+
mini-interactions edge-safe interaction runtime + REST/builders
|
|
237
|
+
mini-interactions/database optional MongoDB persistence
|
|
238
|
+
mini-interactions/oauth2 OAuth2 client and typed scope registry
|
|
239
|
+
mini-interactions/webhooks webhook event verification and routing
|
|
240
|
+
mini-interactions/node legacy Node/Vercel compatibility layer
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The core package has no MongoDB, Node filesystem, or Vercel-specific runtime dependency. Module boundaries use structural interfaces, so `OAuthTokenStorage` can use `mini-interactions/database` or your own database implementation.
|
|
244
|
+
|
|
245
|
+
## Security notes
|
|
246
|
+
|
|
247
|
+
- Every interaction request is Ed25519-verified before dispatch.
|
|
248
|
+
- Ping interactions are answered before application handlers run.
|
|
249
|
+
- OAuth state must be validated by your callback flow; never exchange a code when the state cookie/query parameter is absent or mismatched.
|
|
250
|
+
- Bot tokens and client secrets belong in platform secrets, not in source control.
|
|
251
|
+
|
|
252
|
+
## License
|
|
253
|
+
|
|
254
|
+
MIT © Minesa
|
package/dist/bot.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { CommandBuilder } from "./commands/CommandBuilder.js";
|
|
2
|
+
import { AppCommandBuilder, MessageCommandBuilder, UserCommandBuilder } from "./commands/ContextMenuCommandBuilder.js";
|
|
3
|
+
import { DiscordRestClient, type DiscordRestClientOptions } from "./core/http/DiscordRestClient.js";
|
|
4
|
+
import { InteractionRouter, type AutocompleteHandler, type ChatInputHandler, type ComponentHandler, type EntryPointHandler, type MessageMenuHandler, type ModalHandler, type RouterErrorHandler, type RouterFallback, type RouterMiddleware, type UserMenuHandler } from "./router/InteractionRouter.js";
|
|
5
|
+
export type BotEnvironment = Record<string, string | undefined>;
|
|
6
|
+
export type CreateBotOptions = {
|
|
7
|
+
publicKey?: string;
|
|
8
|
+
applicationId?: string;
|
|
9
|
+
token?: string;
|
|
10
|
+
guildId?: string;
|
|
11
|
+
rest?: DiscordRestClient;
|
|
12
|
+
apiBaseUrl?: DiscordRestClientOptions["apiBaseUrl"];
|
|
13
|
+
maxRetries?: DiscordRestClientOptions["maxRetries"];
|
|
14
|
+
fetchImplementation?: DiscordRestClientOptions["fetchImplementation"];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A small, edge-safe Discord interactions bot.
|
|
18
|
+
*
|
|
19
|
+
* The same instance works as a Fetch API handler in Cloudflare Workers,
|
|
20
|
+
* Vercel Edge/Node functions, Next.js route handlers, Bun, Deno, and modern Node.
|
|
21
|
+
*/
|
|
22
|
+
export declare class MiniBot {
|
|
23
|
+
readonly router: InteractionRouter;
|
|
24
|
+
private readonly options;
|
|
25
|
+
private readonly commandPayloads;
|
|
26
|
+
private restClient?;
|
|
27
|
+
private restClientKey?;
|
|
28
|
+
constructor(options?: CreateBotOptions);
|
|
29
|
+
command(name: string, handler: ChatInputHandler): this;
|
|
30
|
+
command(command: CommandBuilder, handler: ChatInputHandler): this;
|
|
31
|
+
userCommand(name: string, handler: UserMenuHandler): this;
|
|
32
|
+
userCommand(command: UserCommandBuilder, handler: UserMenuHandler): this;
|
|
33
|
+
messageCommand(name: string, handler: MessageMenuHandler): this;
|
|
34
|
+
messageCommand(command: MessageCommandBuilder, handler: MessageMenuHandler): this;
|
|
35
|
+
entryPointCommand(name: string, handler: EntryPointHandler): this;
|
|
36
|
+
entryPointCommand(command: AppCommandBuilder, handler: EntryPointHandler): this;
|
|
37
|
+
component(customIdOrPattern: string | RegExp, handler: ComponentHandler): this;
|
|
38
|
+
modal(customId: string, handler: ModalHandler): this;
|
|
39
|
+
autocomplete(commandName: string, handler: AutocompleteHandler): this;
|
|
40
|
+
use(middleware: RouterMiddleware): this;
|
|
41
|
+
onError(handler: RouterErrorHandler): this;
|
|
42
|
+
onFallback(handler: RouterFallback): this;
|
|
43
|
+
/**
|
|
44
|
+
* Fetch API entrypoint. Use directly as `export const POST = bot.fetch` or
|
|
45
|
+
* pass it to a Cloudflare/Vercel/Node fetch adapter.
|
|
46
|
+
*/
|
|
47
|
+
readonly fetch: (request: Request, env?: BotEnvironment) => Promise<Response>;
|
|
48
|
+
/**
|
|
49
|
+
* Replaces the globally or guild-visible Discord command list with the
|
|
50
|
+
* builder-defined commands registered on this bot.
|
|
51
|
+
*/
|
|
52
|
+
syncCommands(env?: BotEnvironment): Promise<unknown>;
|
|
53
|
+
private setCommandPayload;
|
|
54
|
+
private defaultResponse;
|
|
55
|
+
private resolveCredentials;
|
|
56
|
+
private getRestClient;
|
|
57
|
+
}
|
|
58
|
+
export declare function createBot(options?: CreateBotOptions): MiniBot;
|
package/dist/bot.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { ApplicationCommandType, InteractionResponseType, InteractionType, } from "discord-api-types/v10";
|
|
2
|
+
import { DiscordRestClient } from "./core/http/DiscordRestClient.js";
|
|
3
|
+
import { InteractionContext } from "./core/interactions/InteractionContext.js";
|
|
4
|
+
import { verifyAndParseInteraction } from "./core/interactions/InteractionVerifier.js";
|
|
5
|
+
import { InteractionRouter, } from "./router/InteractionRouter.js";
|
|
6
|
+
function processEnvironment() {
|
|
7
|
+
return typeof process === "undefined" ? undefined : process.env;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A small, edge-safe Discord interactions bot.
|
|
11
|
+
*
|
|
12
|
+
* The same instance works as a Fetch API handler in Cloudflare Workers,
|
|
13
|
+
* Vercel Edge/Node functions, Next.js route handlers, Bun, Deno, and modern Node.
|
|
14
|
+
*/
|
|
15
|
+
export class MiniBot {
|
|
16
|
+
router;
|
|
17
|
+
options;
|
|
18
|
+
commandPayloads = new Map();
|
|
19
|
+
restClient;
|
|
20
|
+
restClientKey;
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.router = new InteractionRouter({
|
|
24
|
+
rest: () => this.options.rest ?? this.restClient,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
command(nameOrCommand, handler) {
|
|
28
|
+
if (typeof nameOrCommand === "string") {
|
|
29
|
+
this.router.onCommand(nameOrCommand, handler);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
const payload = nameOrCommand.toJSON();
|
|
33
|
+
this.setCommandPayload(payload);
|
|
34
|
+
this.router.onCommand(payload.name, handler);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
userCommand(nameOrCommand, handler) {
|
|
38
|
+
if (typeof nameOrCommand === "string") {
|
|
39
|
+
this.router.onUserCommand(nameOrCommand, handler);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
const payload = nameOrCommand.toJSON();
|
|
43
|
+
this.setCommandPayload(payload);
|
|
44
|
+
this.router.onUserCommand(payload.name, handler);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
messageCommand(nameOrCommand, handler) {
|
|
48
|
+
if (typeof nameOrCommand === "string") {
|
|
49
|
+
this.router.onMessageCommand(nameOrCommand, handler);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
const payload = nameOrCommand.toJSON();
|
|
53
|
+
this.setCommandPayload(payload);
|
|
54
|
+
this.router.onMessageCommand(payload.name, handler);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
entryPointCommand(nameOrCommand, handler) {
|
|
58
|
+
if (typeof nameOrCommand === "string") {
|
|
59
|
+
this.router.onEntryPointCommand(nameOrCommand, handler);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
const payload = nameOrCommand.toJSON();
|
|
63
|
+
this.setCommandPayload(payload);
|
|
64
|
+
this.router.onEntryPointCommand(payload.name, handler);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
component(customIdOrPattern, handler) {
|
|
68
|
+
this.router.onComponent(customIdOrPattern, handler);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
modal(customId, handler) {
|
|
72
|
+
this.router.onModal(customId, handler);
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
autocomplete(commandName, handler) {
|
|
76
|
+
this.router.onAutocomplete(commandName, handler);
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
use(middleware) {
|
|
80
|
+
this.router.use(middleware);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
onError(handler) {
|
|
84
|
+
this.router.onError(handler);
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
onFallback(handler) {
|
|
88
|
+
this.router.onFallback(handler);
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Fetch API entrypoint. Use directly as `export const POST = bot.fetch` or
|
|
93
|
+
* pass it to a Cloudflare/Vercel/Node fetch adapter.
|
|
94
|
+
*/
|
|
95
|
+
fetch = async (request, env = {}) => {
|
|
96
|
+
if (request.method !== "POST") {
|
|
97
|
+
return Response.json({ error: "Method not allowed" }, { status: 405 });
|
|
98
|
+
}
|
|
99
|
+
const signature = request.headers.get("x-signature-ed25519");
|
|
100
|
+
const timestamp = request.headers.get("x-signature-timestamp");
|
|
101
|
+
if (!signature || !timestamp) {
|
|
102
|
+
return Response.json({ error: "Missing Discord signature headers" }, { status: 401 });
|
|
103
|
+
}
|
|
104
|
+
const credentials = this.resolveCredentials(env);
|
|
105
|
+
if (!credentials.publicKey) {
|
|
106
|
+
return Response.json({ error: "Missing DISCORD_PUBLIC_KEY" }, { status: 500 });
|
|
107
|
+
}
|
|
108
|
+
let interaction;
|
|
109
|
+
try {
|
|
110
|
+
interaction = await verifyAndParseInteraction({
|
|
111
|
+
body: await request.text(),
|
|
112
|
+
signature,
|
|
113
|
+
timestamp,
|
|
114
|
+
publicKey: credentials.publicKey,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
return Response.json({ error: error instanceof SyntaxError ? "Malformed interaction JSON" : "Invalid interaction signature" }, { status: error instanceof SyntaxError ? 400 : 401 });
|
|
119
|
+
}
|
|
120
|
+
if (interaction.type === InteractionType.Ping) {
|
|
121
|
+
return Response.json({ type: InteractionResponseType.Pong });
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const context = new InteractionContext({
|
|
125
|
+
interaction,
|
|
126
|
+
rest: this.getRestClient(credentials),
|
|
127
|
+
});
|
|
128
|
+
const response = await this.router.dispatch(interaction, context);
|
|
129
|
+
return Response.json(response ?? this.defaultResponse(interaction, context));
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
console.error("[mini-interactions] interaction handler failed", error);
|
|
133
|
+
return Response.json({ error: "Interaction handler failed" }, { status: 500 });
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Replaces the globally or guild-visible Discord command list with the
|
|
138
|
+
* builder-defined commands registered on this bot.
|
|
139
|
+
*/
|
|
140
|
+
async syncCommands(env = {}) {
|
|
141
|
+
const credentials = this.resolveCredentials(env);
|
|
142
|
+
const applicationId = credentials.applicationId;
|
|
143
|
+
const token = credentials.token;
|
|
144
|
+
if (!applicationId || !token) {
|
|
145
|
+
throw new Error("[mini-interactions] syncCommands requires applicationId and token (or DISCORD_APPLICATION_ID and DISCORD_BOT_TOKEN).");
|
|
146
|
+
}
|
|
147
|
+
const rest = this.getRestClient(credentials);
|
|
148
|
+
if (!rest) {
|
|
149
|
+
throw new Error("[mini-interactions] Unable to create a Discord REST client.");
|
|
150
|
+
}
|
|
151
|
+
const route = credentials.guildId
|
|
152
|
+
? `/applications/${applicationId}/guilds/${credentials.guildId}/commands`
|
|
153
|
+
: `/applications/${applicationId}/commands`;
|
|
154
|
+
return rest.request(route, {
|
|
155
|
+
method: "PUT",
|
|
156
|
+
body: JSON.stringify([...this.commandPayloads.values()]),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
setCommandPayload(payload) {
|
|
160
|
+
const type = payload.type ?? ApplicationCommandType.ChatInput;
|
|
161
|
+
this.commandPayloads.set(`${type}:${payload.name}`, payload);
|
|
162
|
+
}
|
|
163
|
+
defaultResponse(interaction, context) {
|
|
164
|
+
if (interaction.type === InteractionType.ApplicationCommandAutocomplete) {
|
|
165
|
+
return {
|
|
166
|
+
type: InteractionResponseType.ApplicationCommandAutocompleteResult,
|
|
167
|
+
data: { choices: [] },
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
if (interaction.type === InteractionType.MessageComponent) {
|
|
171
|
+
return { type: InteractionResponseType.DeferredMessageUpdate };
|
|
172
|
+
}
|
|
173
|
+
return context.deferReply();
|
|
174
|
+
}
|
|
175
|
+
resolveCredentials(env) {
|
|
176
|
+
const processEnv = processEnvironment();
|
|
177
|
+
return {
|
|
178
|
+
publicKey: this.options.publicKey ??
|
|
179
|
+
env.DISCORD_PUBLIC_KEY ??
|
|
180
|
+
processEnv?.DISCORD_PUBLIC_KEY,
|
|
181
|
+
applicationId: this.options.applicationId ??
|
|
182
|
+
env.DISCORD_APPLICATION_ID ??
|
|
183
|
+
env.DISCORD_APP_ID ??
|
|
184
|
+
processEnv?.DISCORD_APPLICATION_ID ??
|
|
185
|
+
processEnv?.DISCORD_APP_ID,
|
|
186
|
+
token: this.options.token ??
|
|
187
|
+
env.DISCORD_BOT_TOKEN ??
|
|
188
|
+
env.DISCORD_TOKEN ??
|
|
189
|
+
processEnv?.DISCORD_BOT_TOKEN ??
|
|
190
|
+
processEnv?.DISCORD_TOKEN,
|
|
191
|
+
guildId: this.options.guildId ??
|
|
192
|
+
env.DISCORD_GUILD_ID ??
|
|
193
|
+
processEnv?.DISCORD_GUILD_ID,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
getRestClient(credentials) {
|
|
197
|
+
if (this.options.rest)
|
|
198
|
+
return this.options.rest;
|
|
199
|
+
if (!credentials.applicationId || !credentials.token)
|
|
200
|
+
return undefined;
|
|
201
|
+
const key = `${credentials.applicationId}:${credentials.token}`;
|
|
202
|
+
if (this.restClient && this.restClientKey === key)
|
|
203
|
+
return this.restClient;
|
|
204
|
+
this.restClient = new DiscordRestClient({
|
|
205
|
+
applicationId: credentials.applicationId,
|
|
206
|
+
token: credentials.token,
|
|
207
|
+
apiBaseUrl: this.options.apiBaseUrl,
|
|
208
|
+
maxRetries: this.options.maxRetries,
|
|
209
|
+
fetchImplementation: this.options.fetchImplementation,
|
|
210
|
+
});
|
|
211
|
+
this.restClientKey = key;
|
|
212
|
+
return this.restClient;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
export function createBot(options = {}) {
|
|
216
|
+
return new MiniBot(options);
|
|
217
|
+
}
|