nuxt-discord 0.0.17 → 0.1.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.
Files changed (112) hide show
  1. package/README.md +249 -171
  2. package/dist/module.d.mts +108 -10
  3. package/dist/module.json +3 -3
  4. package/dist/module.mjs +966 -345
  5. package/dist/runtime/acknowledgement.d.ts +10 -0
  6. package/dist/runtime/acknowledgement.js +124 -0
  7. package/dist/runtime/client/chat-theme.css +52 -0
  8. package/dist/runtime/client/components/ChatAvatar.d.vue.ts +6 -0
  9. package/dist/runtime/client/components/ChatAvatar.vue +11 -0
  10. package/dist/runtime/client/components/ChatAvatar.vue.d.ts +6 -0
  11. package/dist/runtime/client/components/CommandPicker.d.vue.ts +24 -0
  12. package/dist/runtime/client/components/CommandPicker.vue +67 -0
  13. package/dist/runtime/client/components/CommandPicker.vue.d.ts +24 -0
  14. package/dist/runtime/client/components/CommandTestBar.d.vue.ts +60 -0
  15. package/dist/runtime/client/components/CommandTestBar.vue +335 -0
  16. package/dist/runtime/client/components/CommandTestBar.vue.d.ts +60 -0
  17. package/dist/runtime/client/components/CommandTranscript.d.vue.ts +39 -0
  18. package/dist/runtime/client/components/CommandTranscript.vue +147 -0
  19. package/dist/runtime/client/components/CommandTranscript.vue.d.ts +39 -0
  20. package/dist/runtime/client/components/ProjectLogo.d.vue.ts +3 -0
  21. package/dist/runtime/client/components/ProjectLogo.vue +31 -0
  22. package/dist/runtime/client/components/ProjectLogo.vue.d.ts +3 -0
  23. package/dist/runtime/client/components/TheHeader.d.vue.ts +3 -0
  24. package/dist/runtime/client/components/TheHeader.vue +53 -16
  25. package/dist/runtime/client/components/TheHeader.vue.d.ts +2 -2
  26. package/dist/runtime/client/components/appearance-select.d.ts +17 -0
  27. package/dist/runtime/client/components/appearance-select.js +15 -0
  28. package/dist/runtime/client/pages/activity.d.vue.ts +3 -0
  29. package/dist/runtime/client/pages/activity.vue +202 -0
  30. package/dist/runtime/client/pages/activity.vue.d.ts +3 -0
  31. package/dist/runtime/client/pages/context-menus.d.vue.ts +3 -0
  32. package/dist/runtime/client/pages/context-menus.vue +120 -0
  33. package/dist/runtime/client/pages/context-menus.vue.d.ts +3 -0
  34. package/dist/runtime/client/pages/listeners.d.vue.ts +3 -0
  35. package/dist/runtime/client/pages/listeners.vue +68 -0
  36. package/dist/runtime/client/pages/listeners.vue.d.ts +3 -0
  37. package/dist/runtime/client/pages/overview.d.vue.ts +3 -0
  38. package/dist/runtime/client/pages/overview.vue +280 -0
  39. package/dist/runtime/client/pages/overview.vue.d.ts +3 -0
  40. package/dist/runtime/client/pages/slash-commands.d.vue.ts +3 -0
  41. package/dist/runtime/client/pages/slash-commands.vue +185 -359
  42. package/dist/runtime/client/pages/slash-commands.vue.d.ts +2 -3
  43. package/dist/runtime/client/style.css +4 -1
  44. package/dist/runtime/client/useActivityLog.d.ts +7 -0
  45. package/dist/runtime/client/useActivityLog.js +76 -0
  46. package/dist/runtime/client/useCommandRegistry.d.ts +7 -0
  47. package/dist/runtime/client/useCommandRegistry.js +34 -0
  48. package/dist/runtime/client/useDashboardCatalog.d.ts +5 -0
  49. package/dist/runtime/client/useDashboardCatalog.js +9 -0
  50. package/dist/runtime/dashboard/auth.d.ts +4 -0
  51. package/dist/runtime/dashboard/auth.js +65 -0
  52. package/dist/runtime/dashboard/oauth.d.ts +3 -0
  53. package/dist/runtime/dashboard/oauth.js +151 -0
  54. package/dist/runtime/dashboard/permissions.d.ts +4 -0
  55. package/dist/runtime/dashboard/permissions.js +84 -0
  56. package/dist/runtime/dashboard/signin.d.ts +2 -0
  57. package/dist/runtime/dashboard/signin.js +39 -0
  58. package/dist/runtime/diagnostics.d.ts +4 -0
  59. package/dist/runtime/diagnostics.js +24 -0
  60. package/dist/runtime/discordInvocation.d.ts +14 -0
  61. package/dist/runtime/discordInvocation.js +28 -0
  62. package/dist/runtime/middleware.d.ts +1 -0
  63. package/dist/runtime/middleware.js +12 -0
  64. package/dist/runtime/registration.d.ts +65 -0
  65. package/dist/runtime/registration.js +354 -0
  66. package/dist/runtime/server/api/discord/activity.get.d.ts +2 -0
  67. package/dist/runtime/server/api/discord/activity.get.js +6 -0
  68. package/dist/runtime/server/api/discord/catalog.get.d.ts +2 -0
  69. package/dist/runtime/server/api/discord/catalog.get.js +3 -0
  70. package/dist/runtime/server/api/discord/slash-command/autocomplete.post.d.ts +2 -0
  71. package/dist/runtime/server/api/discord/slash-command/autocomplete.post.js +14 -0
  72. package/dist/runtime/server/api/discord/slash-command/register.post.d.ts +1 -1
  73. package/dist/runtime/server/api/discord/slash-command/register.post.js +1 -1
  74. package/dist/runtime/server/api/discord/slash-command/remote-all.get.d.ts +1 -1
  75. package/dist/runtime/server/api/discord/slash-command/remote-diff.post.d.ts +1 -238
  76. package/dist/runtime/server/api/discord/slash-command/remote-diff.post.js +3 -1
  77. package/dist/runtime/server/api/discord/slash-command/test.post.d.ts +20 -0
  78. package/dist/runtime/server/api/discord/slash-command/test.post.js +19 -0
  79. package/dist/runtime/server/plugins/discord.js +93 -31
  80. package/dist/runtime/server/utils/client.d.ts +59 -246
  81. package/dist/runtime/server/utils/client.js +413 -451
  82. package/dist/runtime/server/utils/defineContextMenu.d.ts +49 -0
  83. package/dist/runtime/server/utils/defineContextMenu.js +12 -0
  84. package/dist/runtime/server/utils/defineListener.d.ts +24 -0
  85. package/dist/runtime/server/utils/defineListener.js +7 -0
  86. package/dist/runtime/server/utils/defineMiddleware.d.ts +29 -0
  87. package/dist/runtime/server/utils/defineMiddleware.js +24 -0
  88. package/dist/runtime/server/utils/describeCommand.d.ts +2 -0
  89. package/dist/runtime/server/utils/describeOption.d.ts +1 -1
  90. package/dist/runtime/server/utils/messageSender.d.ts +37 -0
  91. package/dist/runtime/server/utils/messageSender.js +149 -0
  92. package/dist/runtime/server/utils/middleware/cooldown.d.ts +1 -0
  93. package/dist/runtime/server/utils/middleware/cooldown.js +39 -0
  94. package/dist/runtime/server/utils/middleware/guildOnly.d.ts +1 -0
  95. package/dist/runtime/server/utils/middleware/guildOnly.js +6 -0
  96. package/dist/runtime/server/utils/middleware/ownerOnly.d.ts +1 -0
  97. package/dist/runtime/server/utils/middleware/ownerOnly.js +10 -0
  98. package/dist/runtime/server/utils/middleware/requireRole.d.ts +1 -0
  99. package/dist/runtime/server/utils/middleware/requireRole.js +15 -0
  100. package/dist/runtime/server/utils/reply.d.ts +13 -3
  101. package/dist/runtime/server/utils/reply.js +111 -162
  102. package/dist/runtime/server/utils/simulateInteraction.d.ts +20 -0
  103. package/dist/runtime/server/utils/simulateInteraction.js +127 -0
  104. package/dist/runtime/server/utils/useTextChannel.d.ts +56 -0
  105. package/dist/runtime/server/utils/useTextChannel.js +105 -0
  106. package/dist/types.d.mts +11 -1
  107. package/dist/types.d.ts +11 -1
  108. package/package.json +62 -44
  109. package/dist/runtime/client/components/TheHeader.css +0 -1
  110. package/dist/runtime/client/pages/slash-commands.css +0 -1
  111. package/dist/runtime/client/uno.config.d.ts +0 -2
  112. package/dist/runtime/client/uno.config.js +0 -10
package/README.md CHANGED
@@ -1,289 +1,367 @@
1
- # <span style="color:oklch(72.3% 0.219 149.579)">Nuxt</span> <span style="color:#5865F2">Discord</span>
1
+ <img src="./docs/public/logo.svg" width="84" height="84" alt="">
2
+
3
+ # Nuxt Discord
2
4
 
3
5
  [![npm version][npm-version-src]][npm-version-href]
4
6
  [![License][license-src]][license-href]
5
7
  [![Nuxt][nuxt-src]][nuxt-href]
6
8
 
7
- A Nuxt module for building Discord bots with slash commands, featuring hot module replacement, automatic command registration, and web interface for command management.
9
+ Turn TypeScript functions in your Nuxt app into Discord slash commands. Share server code with your bot, register commands automatically, and try them in a local dashboard.
10
+
11
+ - **[Try the live playground](https://zojize.github.io/nuxt-discord/playground/)** — Run `/add`, enter two numbers, and open the sent command to inspect its arguments. The demo runs in your browser.
12
+ - **[Browse the example bot’s command reference](https://zojize.github.io/nuxt-discord/example-bot/)** — Explore the slash commands, options, and context menus generated from the example bot’s source.
8
13
 
9
14
  ## Features
10
15
 
11
- - 🤖 **Discord Bot Integration** - Seamlessly integrate Discord.js with your Nuxt application
12
- - ⚡ **Slash Commands** - Type-safe slash command definitions with automatic registration
13
- - 🎯 **Auto-sync** - Automatically sync commands with Discord's servers
14
- - 🖥️ **Web Interface** - Beautiful UI for managing and viewing slash commands
15
- - 🔄 **Real-time Updates** - WebSocket-based live updates in development
16
+ - **Slash Commands** - Type-safe definitions with automatic registration
17
+ - **Context Menus** - User and message context menus via `defineUserContextMenu` / `defineMessageContextMenu`
18
+ - **Event Listeners** - File-based listeners via `defineListener`
19
+ - **Middleware** - tRPC-inspired `next()` chain with `defineMiddleware`, `useMiddleware` macro, and `@middleware` JSDoc tags
20
+ - **Modals** - Interactive forms via `reply.modal(title, fields, onSubmit)`
21
+ - **Channel Composable** - `useTextChannel` exposes a Discord text channel as a reactive proxy with event-driven refs and a `send()` method
22
+ - **File-based Routing** - Directory structure maps to subcommand hierarchy
23
+ - **All Option Types** - String, Number, Integer, Boolean, User, Channel, Role, Mentionable, Attachment
24
+ - **JSDoc Metadata** - `@nsfw`, `@guild`, `@dm`, `@defaultMemberPermissions`, `@middleware` tags
25
+ - **Localization** - i18n via inline JSDoc or `discord/locales/*.json` files
26
+ - **Guild Commands** - Register commands per-guild for instant updates
27
+ - **Hot reload** - Edit commands while the development bot is running. See [hot reload and shared state](#hot-reload-and-shared-state) for state lifetime.
28
+ - **Web Dashboard** - Overview, commands, context menus, listeners, and live activity log
29
+ - **Built-in Middleware** - `guildOnly`, `ownerOnly`, `cooldown`, `requireRole`
16
30
 
17
31
  ## Quick Setup
18
32
 
19
- Install the module to your Nuxt application:
20
-
21
33
  ```bash
22
- pnpm install nuxt-discord discord.js
34
+ bun add nuxt-discord discord.js
23
35
  ```
24
36
 
25
- Add the module to your `nuxt.config.ts`:
26
-
27
37
  ```ts
38
+ // nuxt.config.ts
28
39
  export default defineNuxtConfig({
29
40
  modules: ['nuxt-discord'],
30
41
  discord: {
31
- // Discord bot configuration
32
- client: {
33
- intents: ['Guilds'], // Discord gateway intents
34
- deferOnPromise: true, // Auto-defer interactions when command returns a promise
35
- },
36
- dir: 'discord', // Directory for Discord-related files
37
- autoStart: true, // Auto-start the bot on server startup
42
+ autoStart: true,
38
43
  watch: {
39
- enabled: true, // Enable HMR for commands
40
- port: 5720, // HMR server port
41
- showURL: false, // Show HMR server URL in console
42
- sync: {
43
- debounce: 1000 // Sync delay in milliseconds
44
- }
45
- }
46
- }
44
+ sync: { debounce: 1000 },
45
+ },
46
+ },
47
47
  })
48
48
  ```
49
49
 
50
- Set up your environment variables:
51
-
52
50
  ```bash
53
51
  # .env
54
- DISCORD_TOKEN=your_bot_token_here
55
- DISCORD_CLIENT_ID=your_application_id_here
52
+ DISCORD_TOKEN=your_bot_token
53
+ DISCORD_CLIENT_ID=your_application_id
56
54
  ```
57
55
 
58
- ## Creating Slash Commands
56
+ For production, deploy the whole `.output` directory to one always-on Node process. Set `DISCORD_TOKEN` and `DISCORD_CLIENT_ID` in the service environment and run `node .output/server/index.mjs`. For a local production run, use `node --env-file=.env .output/server/index.mjs`. [Deployment guide](https://zojize.github.io/nuxt-discord/installation/#deployment)
57
+
58
+ ## Creating Commands
59
59
 
60
- Create slash commands in the `/discord/commands` directory:
60
+ Create files in `discord/commands/`:
61
61
 
62
62
  ```ts
63
63
  // discord/commands/ping.ts
64
- /**
65
- * @name ping
66
- * @description A simple ping command that responds with 'pong!'
67
- */
64
+
65
+ /** A simple ping command */
68
66
  export default function ping() {
69
67
  return 'pong!'
70
68
  }
71
69
  ```
72
70
 
73
- Defining a command this way this module automatically deduces the name and description from the JSDoc comments. The command name is inferred following this set of priorities: `describeCommand` macro > `@name` JSDoc tag > function name > file name.
71
+ The description is inferred from the JSDoc body text. Name priority: `describeCommand` macro > `@name` tag > function name > file name.
74
72
 
75
- ### Commands with Parameters
73
+ ### Parameters
74
+
75
+ Types are inferred from TypeScript signatures:
76
76
 
77
77
  ```ts
78
78
  // discord/commands/add.ts
79
+
79
80
  /**
80
- * @name add
81
- * @description Adds two numbers together
82
- * @param a The first number to add
83
- * @param b The second number to add
81
+ * Adds two numbers together
82
+ * @param a The first number
83
+ * @param b The second number
84
84
  */
85
85
  export default (a: number, b: number) => {
86
- // Add parameter validation
87
- describeOption(a, {
88
- min: -100,
89
- max: 100,
90
- })
86
+ describeOption(a, { min: -100, max: 100 })
87
+ describeOption(b, { min: -100, max: 100 })
88
+ return `${a} + ${b} = ${a + b}`
89
+ }
90
+ ```
91
91
 
92
- describeOption(b, {
93
- min: -100,
94
- max: 100,
95
- })
92
+ All Discord option types are supported:
93
+
94
+ ```ts
95
+ import type { Attachment, Channel, Role, User } from 'discord.js'
96
+ import type { integer, Mentionable } from 'nuxt-discord/types'
97
+
98
+ export default (
99
+ name: string, // String option
100
+ count: number, // Number option
101
+ sides: integer, // Integer option (phantom type)
102
+ verbose: boolean, // Boolean option
103
+ user: User, // User option
104
+ channel: Channel, // Channel option
105
+ role: Role, // Role option
106
+ target: Mentionable, // Mentionable option
107
+ file: Attachment, // Attachment option
108
+ ) => { /* ... */ }
109
+ ```
110
+
111
+ ### Union Types as Choices
96
112
 
97
- return `The sum of ${a} and ${b} is ${a + b}!`
113
+ ```ts
114
+ export default (color: 'red' | 'green' | 'blue') => {
115
+ return `You picked ${color}`
98
116
  }
99
117
  ```
100
118
 
101
- ### String Parameters with Choices
119
+ ### Subcommands
120
+
121
+ Directory structure maps to Discord's subcommand hierarchy:
122
+
123
+ ```
124
+ discord/commands/
125
+ channel.ts # /channel (parent)
126
+ channel/
127
+ send.ts # /channel send
128
+ members.ts # /channel members (group)
129
+ members/
130
+ count.ts # /channel members count
131
+ names.ts # /channel members names
132
+ ```
133
+
134
+ ## Command Metadata
135
+
136
+ Use JSDoc tags to configure command properties:
102
137
 
103
138
  ```ts
104
- // discord/commands/greet.ts
105
139
  /**
106
- * @name greet
107
- * @description Greet someone with a custom message
108
- * @param name The person to greet
109
- * @param style The greeting style
140
+ * Admin-only moderation command
141
+ * @nsfw
142
+ * @guild
143
+ * @dm false
144
+ * @defaultMemberPermissions 8
110
145
  */
111
- export default (name: string, style: string) => {
112
- describeOption(name, {
113
- minLength: 1,
114
- maxLength: 32,
115
- })
146
+ export default () => {
147
+ return reply.ephemeral('Secret admin action!')
148
+ }
149
+ ```
116
150
 
117
- describeOption(style, {
118
- choices: [
119
- { name: 'Formal', value: 'formal' },
120
- { name: 'Casual', value: 'casual' },
121
- { name: 'Enthusiastic', value: 'enthusiastic' },
122
- ],
123
- })
151
+ | Tag | Effect |
152
+ |---|---|
153
+ | `@nsfw` | Mark as age-restricted |
154
+ | `@guild` | Register to all configured guilds (instant updates) |
155
+ | `@guild <id>` | Register to a specific guild by ID |
156
+ | `@dm false` | Disable in DMs |
157
+ | `@defaultMemberPermissions <bits>` | Require permissions (e.g. `8` = Administrator) |
158
+ | `@name.<locale> <text>` | Inline localized name (e.g. `@name.ja ピング`) |
159
+ | `@description.<locale> <text>` | Inline localized description |
124
160
 
125
- const greetings = {
126
- formal: `Good day, ${name}.`,
127
- casual: `Hey ${name}!`,
128
- enthusiastic: `HELLO THERE ${name.toUpperCase()}!!! 🎉`,
129
- } as const
161
+ ### Guild Commands
130
162
 
131
- return greetings[style as keyof typeof greetings]
132
- }
163
+ ```ts
164
+ /** @guild */ // all configured guilds
165
+ /** @guild 123456789012345678 */ // specific guild
166
+ /**
167
+ * @guild 111111111111111111
168
+ * @guild 222222222222222222
169
+ */ // multiple guilds
133
170
  ```
134
171
 
135
- ## Web Interface
172
+ For bare `@guild`, configure target guilds via `DISCORD_GUILD_ID` env var or `discord.guilds` in nuxt.config.
136
173
 
137
- Access the command management interface at `/discord/slash-commands` in your application. The interface provides:
174
+ ## Localization
138
175
 
139
- - 📋 **Command Overview** - View all registered commands with their parameters
140
- - 🏷️ **Parameter Details** - See type information, validation rules, and constraints
141
- - 🔄 **Sync Commands** - Monitor local commands' synced status with server
142
- - ➕ **Register Commands** - Easily register newly added commands
143
- - ⚡ **Live Updates** - Real-time updates during development
176
+ ### Inline JSDoc
144
177
 
145
- > **Coming Soon:** Live command execution/testing, i18n support, logging dashboard, and more fine-grained client control
178
+ ```ts
179
+ /**
180
+ * A ping command
181
+ * @name.ja ピング
182
+ * @description.ja ポンと返すコマンド
183
+ * @description.fr Renvoie pong
184
+ */
185
+ export default () => 'pong!'
186
+ ```
146
187
 
147
- ## Advanced Usage & Customization
188
+ ### JSON Locale Files
189
+
190
+ Create files in `discord/locales/` named after Discord locale codes:
191
+
192
+ ```json
193
+ // discord/locales/ja.json
194
+ {
195
+ "ping": {
196
+ "name": "ピング",
197
+ "description": "ポンと返すコマンド"
198
+ },
199
+ "add": {
200
+ "description": "2つの数を足す",
201
+ "options": {
202
+ "a": { "description": "最初の数" }
203
+ }
204
+ }
205
+ }
206
+ ```
148
207
 
149
- The module is highly customizable and provides access to the internal Discord client and runtime hooks for advanced use cases.
208
+ Inline JSDoc tags take precedence over JSON files. Both can coexist.
150
209
 
151
- ### Using the Discord Client in Server
210
+ ## Response Types
152
211
 
153
212
  ```ts
154
- import { useDiscordClient } from '#imports'
213
+ // Simple string
214
+ export default () => 'Hello!'
215
+
216
+ // Ephemeral (only visible to user)
217
+ export default () => reply.ephemeral('Secret!')
218
+
219
+ // With files
220
+ export default () => reply.file('hello.txt').send('Here is your file')
221
+
222
+ // Reactive (auto-edits when ref changes)
223
+ export default () => {
224
+ const msg = ref('Loading...')
225
+ setTimeout(() => {
226
+ msg.value = 'Done!'
227
+ }, 2000)
228
+ return msg
229
+ }
155
230
 
156
- export default async () => {
157
- const client = useDiscordClient()
231
+ // Generator (multiple replies)
232
+ export default function* () {
233
+ yield 'First message'
234
+ yield 'Follow-up'
235
+ }
158
236
 
159
- // Access the internal Discord.js client
160
- const discordJS = client.internalClient
161
- const guilds = discordJS?.guilds.cache.size || 0
237
+ // Interactive buttons
238
+ export default () => {
239
+ const count = ref(0)
240
+ return reply
241
+ .button('+1', () => { count.value++ })
242
+ .send(computed(() => `Count: ${count.value}`))
243
+ }
244
+ ```
162
245
 
163
- return `Bot is in ${guilds} servers!`
246
+ ## Middleware
247
+
248
+ ```ts
249
+ // discord/commands/admin.ts
250
+
251
+ /** @middleware guildOnly */
252
+ export default () => {
253
+ useMiddleware(cooldown, { seconds: 10 })
254
+ return reply.ephemeral('Admin action executed!')
164
255
  }
165
256
  ```
166
257
 
167
- ### Runtime Hooks
258
+ Built-in middleware: `guildOnly`, `ownerOnly`, `cooldown`, `requireRole`. Create your own with `defineMiddleware`:
259
+
260
+ ```ts
261
+ export const withUser = defineMiddleware('withUser', async ({ interaction, next }) => {
262
+ const user = await db.getUser(interaction.user.id)
263
+ if (!user)
264
+ throw new MiddlewareError('Please register first.')
265
+ return next({ user }) // pass data to the command
266
+ })
267
+ ```
268
+
269
+ ## Web Dashboard
168
270
 
169
- The module provides several hooks for customizing bot behavior:
271
+ Start the Nuxt dev server and open `/discord`, or [host a private dashboard](docs/content/dashboard.md#hosting-a-private-dashboard) alongside your production bot.
272
+
273
+ - **Overview** - Stat cards for commands, context menus, listeners
274
+ - **Slash Commands** - Option types, sync status, one-click sync, command test bar with parameter autocomplete
275
+ - **Context Menus** - User and message menus grouped by type
276
+ - **Listeners** - Event names and once flags
277
+ - **Activity Log** - Real-time interaction history with filtering and stats
278
+
279
+ In development, file paths link to your editor.
280
+
281
+ ### Hot reload and shared state
282
+
283
+ Editing a command updates its handler in the running bot. Commands can share a server helper’s in-memory state across command edits, including when the helper is auto-imported or reached through a project alias. Nitro imports such as `useStorage` continue to use the running server.
284
+
285
+ Keep data that must survive a restart, such as a per-user pull count, in a database or a persistent Nitro storage mount. A full Nitro server reload starts a new worker and resets module-level counters.
286
+
287
+ ## Runtime Hooks
170
288
 
171
289
  ```ts
172
- // nitro/plugins/discord-config.ts
290
+ // server/plugins/discord.ts
173
291
  export default defineNitroPlugin(async (nitro) => {
174
- // Configure Discord client options
175
292
  nitro.hooks.hook('discord:client:config', (options) => {
176
293
  options.presence = {
177
294
  status: 'online',
178
- activities: [{
179
- name: 'Powered by Nuxt',
180
- }]
295
+ activities: [{ name: 'Powered by Nuxt' }],
181
296
  }
182
297
  })
183
298
 
184
- // Handle client ready event
185
299
  nitro.hooks.hook('discord:client:ready', (client) => {
186
- console.log('Discord bot is ready!')
300
+ console.log('Bot is ready!')
187
301
  })
188
302
 
189
- // Handle client errors
190
303
  nitro.hooks.hook('discord:client:error', (error) => {
191
304
  console.error('Discord error:', error)
192
305
  })
193
306
  })
194
307
  ```
195
308
 
196
- ### Custom Response Handling
309
+ ## Server-side Client Access
197
310
 
198
311
  ```ts
199
- export default (message: string) => {
200
- // Return different response types
201
- return reply.ephemeral(`This is private: ${message}`) // Only visible to user
202
- // or
203
- return `Public response: ${message}` // Visible to everyone
312
+ export default async () => {
313
+ const client = useDiscordClient()
314
+ const guilds = client.internalClient?.guilds.cache.size || 0
315
+ return `Bot is in ${guilds} servers!`
204
316
  }
205
317
  ```
206
318
 
207
- > Refer to [/src/types.ts](/src/types.ts) for detailed type definitions for how you can define commands return types for advanced behavior.
208
-
209
- ## Configuration Options
319
+ ## Configuration
210
320
 
211
321
  ```ts
212
- // nuxt.config.ts
213
322
  export default defineNuxtConfig({
214
323
  discord: {
215
324
  client: {
216
- intents: [
217
- 'Guilds',
218
- 'GuildMessages'
219
- ],
220
- deferOnPromise: true, // Auto-defer interactions when command returns a promise
325
+ intents: ['Guilds', 'GuildMessages'],
326
+ deferOnPromise: true,
221
327
  },
222
328
  dir: 'discord',
223
329
  autoStart: true,
330
+ guilds: [], // Guild IDs for @guild commands
224
331
  watch: {
225
332
  enabled: true,
226
- port: 5720, // HMR server port
227
- showURL: false, // Show HMR server URL in console
228
- sync: {
229
- debounce: 1000
230
- }
231
- }
232
- }
333
+ port: 5720,
334
+ showURL: false,
335
+ sync: { debounce: 1000 },
336
+ },
337
+ },
233
338
  })
234
339
  ```
235
340
 
236
- > Use the 'nitro:client:config' hook to configure other options passed to the Discord client.
237
-
238
- ## Roadmap
239
-
240
- Here's what's planned for future releases:
241
-
242
- ### Core Features
243
-
244
- - [ ] Full slash command options support
245
- - [x] String type
246
- - [x] Number type
247
- - [x] Integer type
248
- - [x] Boolean type
249
- - [ ] Role type
250
- - [ ] User type
251
- - [ ] Mentionable type
252
- - [ ] Attachment type
253
- - [ ] Better JSDocs support JSDoc comments
254
- - [ ] Localization support
255
- - [x] File-based subcommands
256
- - [x] Auto-complete API
257
- - [ ] Guild-specific commands
258
- - [ ] Nuxt-devtools integration
259
- - [ ] Unit tests (WIP)
260
-
261
- ### Web Interface Enhancements
262
-
263
- - [ ] Live command execution
264
- - [ ] Command testing interface
265
- - [ ] i18n management
266
- - [ ] Logging dashboard
267
- - [ ] Detailed client control panel
268
- - [ ] Command analytics
269
- - [ ] Fine grained diff display
270
-
271
341
  ## Contribution
272
342
 
273
- Refer to the official [Module Author Guide](https://nuxt.com/docs/guide/going-further/modules)
343
+ ```bash
344
+ bun install --frozen-lockfile
345
+ bun run dev # Start the example bot and its local dashboard
346
+ bun run test # Run tests
347
+ bun run release:check
348
+ ```
349
+
350
+ To try an already registered command in Discord, set `DISCORD_TOKEN` and `DISCORD_CLIENT_ID` in `playground/.env` and keep the dev server running. Wait for “Discord client is ready!” before sending `/add`. The public site's browser playground runs its examples locally even when the bot is offline.
351
+
352
+ Use Node 24 and the Bun version in `package.json` for development. `bun run release:check` runs the same checks as CI, including TypeScript, Vue templates, integration tests and a build of the public site. It also installs the packed module in a fresh Nuxt app and exercises a production bot with simulated Discord interactions. The check runs without bot credentials.
353
+
354
+ The project uses the native TypeScript 7 compiler for type checking. Vue template checking and the module's source transformations also use the TypeScript 6 JavaScript API.
274
355
 
275
356
  ## Acknowledgement
276
357
 
277
- - Generated from the [module starter template](https://github.com/nuxt/starter/tree/module)
278
- - Implementation details and best practices are inspired by
279
- - [@nuxt/content](https://github.com/nuxt/content)
280
- - [@nuxtjs/i18n](https://github.com/nuxt-modules/i18n)
281
- - [@nuxt/devtools](https://github.com/nuxt/devtools)
282
- - UI components are based on [Nuxt UI](https://ui.nuxt.com/) and [UnoCSS](https://unocss.dev/)
358
+ - Built with the [Nuxt module starter](https://github.com/nuxt/starter/tree/module)
359
+ - Inspired by [@nuxt/content](https://github.com/nuxt/content), [@nuxtjs/i18n](https://github.com/nuxt-modules/i18n), [@nuxt/devtools](https://github.com/nuxt/devtools)
360
+ - UI powered by [Nuxt UI](https://ui.nuxt.com/)
283
361
 
284
362
  ## License
285
363
 
286
- [MIT](./LICENSE) - Made with 💚
364
+ [MIT](./LICENSE)
287
365
 
288
366
  [npm-version-src]: https://img.shields.io/npm/v/nuxt-discord/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
289
367
  [npm-version-href]: https://npmjs.com/package/nuxt-discord