@stonyx/discord 0.1.1-beta.143 → 0.1.1-beta.145
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/README.md +32 -2
- package/dist/base.d.ts +1 -1
- package/dist/base.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ pnpm install @stonyx/discord
|
|
|
23
23
|
|
|
24
24
|
## Quick Start
|
|
25
25
|
|
|
26
|
-
The examples below are complete files: each one imports only from `@stonyx/discord` subpaths, so it runs in an app that depends on nothing but `@stonyx/discord`. The repo's `test/sample/` directory holds
|
|
26
|
+
The examples below are complete files: each one imports only from `@stonyx/discord` subpaths, so it runs in an app that depends on nothing but `@stonyx/discord`. The repo's `test/sample/` directory holds samples written the same way ([source](https://github.com/abofs/stonyx-discord/tree/dev/test/sample)), and the test suite loads and exercises them on every run. See [Samples](#samples) for the list.
|
|
27
27
|
|
|
28
28
|
### 1. Create handler directories
|
|
29
29
|
|
|
@@ -87,7 +87,7 @@ stonyx serve
|
|
|
87
87
|
| `@stonyx/discord/command` | `Command` (default) — base class for slash commands |
|
|
88
88
|
| `@stonyx/discord/event-handler` | `EventHandler` (default) — base class for gateway event handlers |
|
|
89
89
|
| `@stonyx/discord/message` | `chunkMessage` — message chunking helper |
|
|
90
|
-
| `@stonyx/discord/base` | Re-exports of
|
|
90
|
+
| `@stonyx/discord/base` | Re-exports of discord.js: `SlashCommandBuilder`, `EmbedBuilder`, `ActionRowBuilder`, `ButtonBuilder`, `ButtonStyle`, `MessageFlags`, `PermissionFlagsBits`, `AttachmentBuilder`, `REST`, `Routes`, `Client`, `GatewayIntentBits`, `Partials` |
|
|
91
91
|
|
|
92
92
|
## Command Architecture
|
|
93
93
|
|
|
@@ -120,6 +120,22 @@ The framework wraps `execute()` in a try/catch. On error:
|
|
|
120
120
|
2. Sends an ephemeral "There was an error executing this command!" reply
|
|
121
121
|
3. Uses `followUp` if the interaction was already replied to or deferred
|
|
122
122
|
|
|
123
|
+
### Registering commands with Discord
|
|
124
|
+
|
|
125
|
+
The bot loads your command classes at boot, but it never registers them with Discord. Registration is a separate script you run whenever a command's `data` changes. [`test/sample/scripts/deploy-commands.js`](https://github.com/abofs/stonyx-discord/blob/dev/test/sample/scripts/deploy-commands.js) is a complete one. It loads the command directory and PUTs each command's `data.toJSON()` to `Routes.applicationGuildCommands(applicationId, guildId)` using `REST` from `@stonyx/discord/base`. Guild-scoped commands update immediately, which is what you want in development.
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
DISCORD_TOKEN=... DISCORD_BOT_USER_ID=... DISCORD_SERVER_ID=... node scripts/deploy-commands.js ./discord-commands
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Buttons, autocomplete and other interactions
|
|
132
|
+
|
|
133
|
+
The bot's own `interactionCreate` listener dispatches only chat-input (slash) commands. Buttons, autocomplete, select menus and modals belong to your app: write an event handler with `static event = 'interactionCreate'`. [`test/sample/discord-events/interaction-create.js`](https://github.com/abofs/stonyx-discord/blob/dev/test/sample/discord-events/interaction-create.js) routes autocomplete to the command's `autocomplete(interaction)` and buttons, by `customId`, to the command's `button(interaction, action, argument)`. It leaves chat-input interactions alone so commands do not run twice.
|
|
134
|
+
|
|
135
|
+
### Embeds
|
|
136
|
+
|
|
137
|
+
Build embeds and button rows with `EmbedBuilder`, `ActionRowBuilder`, `ButtonBuilder` and `ButtonStyle` from `@stonyx/discord/base`. [`test/sample/discord-commands/color.js`](https://github.com/abofs/stonyx-discord/blob/dev/test/sample/discord-commands/color.js) replies with an embed and a button, and implements the `autocomplete()` and `button()` methods the router above calls.
|
|
138
|
+
|
|
123
139
|
## Event Handler Architecture
|
|
124
140
|
|
|
125
141
|
### How handlers are discovered
|
|
@@ -341,6 +357,18 @@ Configuration is read from `stonyx/config` under `discord`:
|
|
|
341
357
|
| `handle(...args)` | Handle the event — define in subclass |
|
|
342
358
|
| `this._bot` | Reference to `DiscordBot` (set during discovery) |
|
|
343
359
|
|
|
360
|
+
## Samples
|
|
361
|
+
|
|
362
|
+
Each sample imports only from `@stonyx/discord` subpaths and `node:` builtins, so it can be copied into an app as is. [`test/unit/sample-patterns-test.ts`](https://github.com/abofs/stonyx-discord/blob/dev/test/unit/sample-patterns-test.ts) exercises them with a fake REST client and fake interactions.
|
|
363
|
+
|
|
364
|
+
| Sample | Shows |
|
|
365
|
+
|--------|-------|
|
|
366
|
+
| [`discord-commands/ping.js`](https://github.com/abofs/stonyx-discord/blob/dev/test/sample/discord-commands/ping.js) | A minimal slash command |
|
|
367
|
+
| [`discord-commands/color.js`](https://github.com/abofs/stonyx-discord/blob/dev/test/sample/discord-commands/color.js) | A command with an embed, a button row, `autocomplete()` and `button()` |
|
|
368
|
+
| [`discord-events/log-message.js`](https://github.com/abofs/stonyx-discord/blob/dev/test/sample/discord-events/log-message.js) | A `messageCreate` handler |
|
|
369
|
+
| [`discord-events/interaction-create.js`](https://github.com/abofs/stonyx-discord/blob/dev/test/sample/discord-events/interaction-create.js) | Routing buttons and autocomplete from `interactionCreate` |
|
|
370
|
+
| [`scripts/deploy-commands.js`](https://github.com/abofs/stonyx-discord/blob/dev/test/sample/scripts/deploy-commands.js) | Registering slash commands, guild-scoped, with `REST` and `Routes` |
|
|
371
|
+
|
|
344
372
|
## Example Project Structure
|
|
345
373
|
|
|
346
374
|
```
|
|
@@ -353,6 +381,8 @@ my-app/
|
|
|
353
381
|
├── discord-events/
|
|
354
382
|
│ ├── message-create.js
|
|
355
383
|
│ └── guild-member-add.js
|
|
384
|
+
├── scripts/
|
|
385
|
+
│ └── deploy-commands.js
|
|
356
386
|
├── package.json
|
|
357
387
|
└── app.js
|
|
358
388
|
```
|
package/dist/base.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { SlashCommandBuilder, MessageFlags, PermissionFlagsBits, GatewayIntentBits, AttachmentBuilder, Client, Partials, REST, Routes } from 'discord.js';
|
|
1
|
+
export { SlashCommandBuilder, MessageFlags, PermissionFlagsBits, GatewayIntentBits, AttachmentBuilder, Client, Partials, REST, Routes, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, } from 'discord.js';
|
package/dist/base.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { SlashCommandBuilder, MessageFlags, PermissionFlagsBits, GatewayIntentBits, AttachmentBuilder, Client, Partials, REST, Routes } from 'discord.js';
|
|
1
|
+
export { SlashCommandBuilder, MessageFlags, PermissionFlagsBits, GatewayIntentBits, AttachmentBuilder, Client, Partials, REST, Routes, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, } from 'discord.js';
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"stonyx-async",
|
|
5
5
|
"stonyx-module"
|
|
6
6
|
],
|
|
7
|
-
"version": "0.1.1-beta.
|
|
7
|
+
"version": "0.1.1-beta.145",
|
|
8
8
|
"description": "Discord bot module for the Stonyx framework",
|
|
9
9
|
"main": "dist/main.js",
|
|
10
10
|
"types": "dist/main.d.ts",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@types/sinon": "^21.0.1",
|
|
71
71
|
"qunit": "^2.24.1",
|
|
72
72
|
"sinon": "^21.0.0",
|
|
73
|
-
"stonyx": "0.2.3-beta.
|
|
73
|
+
"stonyx": "0.2.3-beta.102",
|
|
74
74
|
"tsx": "^4.21.0",
|
|
75
75
|
"typescript": "^5.8.3"
|
|
76
76
|
},
|