@stonyx/discord 0.1.1-beta.137 → 0.1.1-beta.139
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 +22 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Discord bot module for the [Stonyx framework](https://github.com/abofs/stonyx),
|
|
|
11
11
|
* **Command auto-discovery:** Drop command files into a directory and the framework registers them automatically.
|
|
12
12
|
* **Event handler auto-discovery:** Same pattern for Discord gateway events.
|
|
13
13
|
* **Intent auto-derivation:** Required intents computed from discovered event handlers.
|
|
14
|
-
* **
|
|
14
|
+
* **Token-gated start:** The bot logs in only when a token is configured. With a token and no commands or events, it still logs in, so a send-only bot works.
|
|
15
15
|
* **Singleton pattern:** Matches conventions of `@stonyx/sockets` and `@stonyx/events`.
|
|
16
16
|
* **Utility methods:** sendMessage, reply with auto-chunking, role management, and more.
|
|
17
17
|
|
|
@@ -23,6 +23,8 @@ 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 a command and an event handler written the same way ([source](https://github.com/abofs/stonyx-discord/tree/dev/test/sample)), and the test suite loads them on every run.
|
|
27
|
+
|
|
26
28
|
### 1. Create handler directories
|
|
27
29
|
|
|
28
30
|
```
|
|
@@ -36,8 +38,8 @@ discord-events/ # default directory (configurable)
|
|
|
36
38
|
|
|
37
39
|
```javascript
|
|
38
40
|
// discord-commands/ping.js
|
|
39
|
-
import { SlashCommandBuilder } from 'discord
|
|
40
|
-
import
|
|
41
|
+
import { SlashCommandBuilder } from '@stonyx/discord/base';
|
|
42
|
+
import Command from '@stonyx/discord/command';
|
|
41
43
|
|
|
42
44
|
export default class PingCommand extends Command {
|
|
43
45
|
data = new SlashCommandBuilder()
|
|
@@ -54,14 +56,14 @@ export default class PingCommand extends Command {
|
|
|
54
56
|
|
|
55
57
|
```javascript
|
|
56
58
|
// discord-events/message-create.js
|
|
57
|
-
import
|
|
59
|
+
import EventHandler from '@stonyx/discord/event-handler';
|
|
58
60
|
|
|
59
61
|
export default class MessageCreateHandler extends EventHandler {
|
|
60
62
|
static event = 'messageCreate';
|
|
61
63
|
|
|
62
|
-
handle(message) {
|
|
64
|
+
async handle(message) {
|
|
63
65
|
if (message.author.bot) return;
|
|
64
|
-
|
|
66
|
+
if (message.content === '!ping') await message.reply('pong');
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
```
|
|
@@ -74,7 +76,18 @@ Stonyx auto-initializes the bot when your app boots — no manual wiring needed:
|
|
|
74
76
|
stonyx serve
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
`Discord.init()` (called by the Stonyx module loader) awaits `new DiscordBot().init()`, which discovers commands/events, derives intents, and connects to the gateway.
|
|
79
|
+
`Discord.init()` (called by the Stonyx module loader) awaits `new DiscordBot().init()`, which discovers commands/events, derives intents, and connects to the gateway. If `DISCORD_TOKEN` is unset, the bot skips login. With a token it always logs in, even when no commands or events exist.
|
|
80
|
+
|
|
81
|
+
## Exports
|
|
82
|
+
|
|
83
|
+
| Import | Provides |
|
|
84
|
+
|--------|----------|
|
|
85
|
+
| `@stonyx/discord` | `Discord` (default) — the Stonyx module entry point; no named exports |
|
|
86
|
+
| `@stonyx/discord/bot` | `DiscordBot` (default) — the bot singleton and its utility methods |
|
|
87
|
+
| `@stonyx/discord/command` | `Command` (default) — base class for slash commands |
|
|
88
|
+
| `@stonyx/discord/event-handler` | `EventHandler` (default) — base class for gateway event handlers |
|
|
89
|
+
| `@stonyx/discord/message` | `chunkMessage` — message chunking helper |
|
|
90
|
+
| `@stonyx/discord/base` | Re-exports of common discord.js classes (`SlashCommandBuilder`, `Client`, `GatewayIntentBits`, `Partials`, ...) |
|
|
78
91
|
|
|
79
92
|
## Command Architecture
|
|
80
93
|
|
|
@@ -148,7 +161,7 @@ The framework automatically computes the required intents from your registered e
|
|
|
148
161
|
| `voiceStateUpdate` | `GuildVoiceStates` |
|
|
149
162
|
| `interactionCreate` | *(none — handled by default)* |
|
|
150
163
|
|
|
151
|
-
**`Guilds` is always included
|
|
164
|
+
**`Guilds` is always included**, whether or not any commands or events are registered.
|
|
152
165
|
|
|
153
166
|
### Intent-to-Partial Mapping
|
|
154
167
|
|
|
@@ -174,7 +187,7 @@ Values are resolved against `GatewayIntentBits` and `Partials` enums from discor
|
|
|
174
187
|
|
|
175
188
|
## Utility Methods
|
|
176
189
|
|
|
177
|
-
All methods are on the `DiscordBot` instance (accessible via `this._bot` in commands/handlers or `new DiscordBot()`).
|
|
190
|
+
All methods are on the `DiscordBot` instance (accessible via `this._bot` in commands/handlers, or `new DiscordBot()` after `import DiscordBot from '@stonyx/discord/bot'`).
|
|
178
191
|
|
|
179
192
|
### sendMessage(content, channelId, imagePath?)
|
|
180
193
|
|