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.
- package/README.md +249 -171
- package/dist/module.d.mts +108 -10
- package/dist/module.json +3 -3
- package/dist/module.mjs +966 -345
- package/dist/runtime/acknowledgement.d.ts +10 -0
- package/dist/runtime/acknowledgement.js +124 -0
- package/dist/runtime/client/chat-theme.css +52 -0
- package/dist/runtime/client/components/ChatAvatar.d.vue.ts +6 -0
- package/dist/runtime/client/components/ChatAvatar.vue +11 -0
- package/dist/runtime/client/components/ChatAvatar.vue.d.ts +6 -0
- package/dist/runtime/client/components/CommandPicker.d.vue.ts +24 -0
- package/dist/runtime/client/components/CommandPicker.vue +67 -0
- package/dist/runtime/client/components/CommandPicker.vue.d.ts +24 -0
- package/dist/runtime/client/components/CommandTestBar.d.vue.ts +60 -0
- package/dist/runtime/client/components/CommandTestBar.vue +335 -0
- package/dist/runtime/client/components/CommandTestBar.vue.d.ts +60 -0
- package/dist/runtime/client/components/CommandTranscript.d.vue.ts +39 -0
- package/dist/runtime/client/components/CommandTranscript.vue +147 -0
- package/dist/runtime/client/components/CommandTranscript.vue.d.ts +39 -0
- package/dist/runtime/client/components/ProjectLogo.d.vue.ts +3 -0
- package/dist/runtime/client/components/ProjectLogo.vue +31 -0
- package/dist/runtime/client/components/ProjectLogo.vue.d.ts +3 -0
- package/dist/runtime/client/components/TheHeader.d.vue.ts +3 -0
- package/dist/runtime/client/components/TheHeader.vue +53 -16
- package/dist/runtime/client/components/TheHeader.vue.d.ts +2 -2
- package/dist/runtime/client/components/appearance-select.d.ts +17 -0
- package/dist/runtime/client/components/appearance-select.js +15 -0
- package/dist/runtime/client/pages/activity.d.vue.ts +3 -0
- package/dist/runtime/client/pages/activity.vue +202 -0
- package/dist/runtime/client/pages/activity.vue.d.ts +3 -0
- package/dist/runtime/client/pages/context-menus.d.vue.ts +3 -0
- package/dist/runtime/client/pages/context-menus.vue +120 -0
- package/dist/runtime/client/pages/context-menus.vue.d.ts +3 -0
- package/dist/runtime/client/pages/listeners.d.vue.ts +3 -0
- package/dist/runtime/client/pages/listeners.vue +68 -0
- package/dist/runtime/client/pages/listeners.vue.d.ts +3 -0
- package/dist/runtime/client/pages/overview.d.vue.ts +3 -0
- package/dist/runtime/client/pages/overview.vue +280 -0
- package/dist/runtime/client/pages/overview.vue.d.ts +3 -0
- package/dist/runtime/client/pages/slash-commands.d.vue.ts +3 -0
- package/dist/runtime/client/pages/slash-commands.vue +185 -359
- package/dist/runtime/client/pages/slash-commands.vue.d.ts +2 -3
- package/dist/runtime/client/style.css +4 -1
- package/dist/runtime/client/useActivityLog.d.ts +7 -0
- package/dist/runtime/client/useActivityLog.js +76 -0
- package/dist/runtime/client/useCommandRegistry.d.ts +7 -0
- package/dist/runtime/client/useCommandRegistry.js +34 -0
- package/dist/runtime/client/useDashboardCatalog.d.ts +5 -0
- package/dist/runtime/client/useDashboardCatalog.js +9 -0
- package/dist/runtime/dashboard/auth.d.ts +4 -0
- package/dist/runtime/dashboard/auth.js +65 -0
- package/dist/runtime/dashboard/oauth.d.ts +3 -0
- package/dist/runtime/dashboard/oauth.js +151 -0
- package/dist/runtime/dashboard/permissions.d.ts +4 -0
- package/dist/runtime/dashboard/permissions.js +84 -0
- package/dist/runtime/dashboard/signin.d.ts +2 -0
- package/dist/runtime/dashboard/signin.js +39 -0
- package/dist/runtime/diagnostics.d.ts +4 -0
- package/dist/runtime/diagnostics.js +24 -0
- package/dist/runtime/discordInvocation.d.ts +14 -0
- package/dist/runtime/discordInvocation.js +28 -0
- package/dist/runtime/middleware.d.ts +1 -0
- package/dist/runtime/middleware.js +12 -0
- package/dist/runtime/registration.d.ts +65 -0
- package/dist/runtime/registration.js +354 -0
- package/dist/runtime/server/api/discord/activity.get.d.ts +2 -0
- package/dist/runtime/server/api/discord/activity.get.js +6 -0
- package/dist/runtime/server/api/discord/catalog.get.d.ts +2 -0
- package/dist/runtime/server/api/discord/catalog.get.js +3 -0
- package/dist/runtime/server/api/discord/slash-command/autocomplete.post.d.ts +2 -0
- package/dist/runtime/server/api/discord/slash-command/autocomplete.post.js +14 -0
- package/dist/runtime/server/api/discord/slash-command/register.post.d.ts +1 -1
- package/dist/runtime/server/api/discord/slash-command/register.post.js +1 -1
- package/dist/runtime/server/api/discord/slash-command/remote-all.get.d.ts +1 -1
- package/dist/runtime/server/api/discord/slash-command/remote-diff.post.d.ts +1 -238
- package/dist/runtime/server/api/discord/slash-command/remote-diff.post.js +3 -1
- package/dist/runtime/server/api/discord/slash-command/test.post.d.ts +20 -0
- package/dist/runtime/server/api/discord/slash-command/test.post.js +19 -0
- package/dist/runtime/server/plugins/discord.js +93 -31
- package/dist/runtime/server/utils/client.d.ts +59 -246
- package/dist/runtime/server/utils/client.js +413 -451
- package/dist/runtime/server/utils/defineContextMenu.d.ts +49 -0
- package/dist/runtime/server/utils/defineContextMenu.js +12 -0
- package/dist/runtime/server/utils/defineListener.d.ts +24 -0
- package/dist/runtime/server/utils/defineListener.js +7 -0
- package/dist/runtime/server/utils/defineMiddleware.d.ts +29 -0
- package/dist/runtime/server/utils/defineMiddleware.js +24 -0
- package/dist/runtime/server/utils/describeCommand.d.ts +2 -0
- package/dist/runtime/server/utils/describeOption.d.ts +1 -1
- package/dist/runtime/server/utils/messageSender.d.ts +37 -0
- package/dist/runtime/server/utils/messageSender.js +149 -0
- package/dist/runtime/server/utils/middleware/cooldown.d.ts +1 -0
- package/dist/runtime/server/utils/middleware/cooldown.js +39 -0
- package/dist/runtime/server/utils/middleware/guildOnly.d.ts +1 -0
- package/dist/runtime/server/utils/middleware/guildOnly.js +6 -0
- package/dist/runtime/server/utils/middleware/ownerOnly.d.ts +1 -0
- package/dist/runtime/server/utils/middleware/ownerOnly.js +10 -0
- package/dist/runtime/server/utils/middleware/requireRole.d.ts +1 -0
- package/dist/runtime/server/utils/middleware/requireRole.js +15 -0
- package/dist/runtime/server/utils/reply.d.ts +13 -3
- package/dist/runtime/server/utils/reply.js +111 -162
- package/dist/runtime/server/utils/simulateInteraction.d.ts +20 -0
- package/dist/runtime/server/utils/simulateInteraction.js +127 -0
- package/dist/runtime/server/utils/useTextChannel.d.ts +56 -0
- package/dist/runtime/server/utils/useTextChannel.js +105 -0
- package/dist/types.d.mts +11 -1
- package/dist/types.d.ts +11 -1
- package/package.json +62 -44
- package/dist/runtime/client/components/TheHeader.css +0 -1
- package/dist/runtime/client/pages/slash-commands.css +0 -1
- package/dist/runtime/client/uno.config.d.ts +0 -2
- package/dist/runtime/client/uno.config.js +0 -10
package/README.md
CHANGED
|
@@ -1,289 +1,367 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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=
|
|
55
|
-
DISCORD_CLIENT_ID=
|
|
52
|
+
DISCORD_TOKEN=your_bot_token
|
|
53
|
+
DISCORD_CLIENT_ID=your_application_id
|
|
56
54
|
```
|
|
57
55
|
|
|
58
|
-
|
|
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
|
|
60
|
+
Create files in `discord/commands/`:
|
|
61
61
|
|
|
62
62
|
```ts
|
|
63
63
|
// discord/commands/ping.ts
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
71
|
+
The description is inferred from the JSDoc body text. Name priority: `describeCommand` macro > `@name` tag > function name > file name.
|
|
74
72
|
|
|
75
|
-
###
|
|
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
|
-
*
|
|
81
|
-
* @
|
|
82
|
-
* @param
|
|
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
|
-
|
|
87
|
-
describeOption(
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
113
|
+
```ts
|
|
114
|
+
export default (color: 'red' | 'green' | 'blue') => {
|
|
115
|
+
return `You picked ${color}`
|
|
98
116
|
}
|
|
99
117
|
```
|
|
100
118
|
|
|
101
|
-
###
|
|
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
|
-
*
|
|
107
|
-
* @
|
|
108
|
-
* @
|
|
109
|
-
* @
|
|
140
|
+
* Admin-only moderation command
|
|
141
|
+
* @nsfw
|
|
142
|
+
* @guild
|
|
143
|
+
* @dm false
|
|
144
|
+
* @defaultMemberPermissions 8
|
|
110
145
|
*/
|
|
111
|
-
export default (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
})
|
|
146
|
+
export default () => {
|
|
147
|
+
return reply.ephemeral('Secret admin action!')
|
|
148
|
+
}
|
|
149
|
+
```
|
|
116
150
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
126
|
-
formal: `Good day, ${name}.`,
|
|
127
|
-
casual: `Hey ${name}!`,
|
|
128
|
-
enthusiastic: `HELLO THERE ${name.toUpperCase()}!!! 🎉`,
|
|
129
|
-
} as const
|
|
161
|
+
### Guild Commands
|
|
130
162
|
|
|
131
|
-
|
|
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
|
-
|
|
172
|
+
For bare `@guild`, configure target guilds via `DISCORD_GUILD_ID` env var or `discord.guilds` in nuxt.config.
|
|
136
173
|
|
|
137
|
-
|
|
174
|
+
## Localization
|
|
138
175
|
|
|
139
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
208
|
+
Inline JSDoc tags take precedence over JSON files. Both can coexist.
|
|
150
209
|
|
|
151
|
-
|
|
210
|
+
## Response Types
|
|
152
211
|
|
|
153
212
|
```ts
|
|
154
|
-
|
|
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
|
-
|
|
157
|
-
|
|
231
|
+
// Generator (multiple replies)
|
|
232
|
+
export default function* () {
|
|
233
|
+
yield 'First message'
|
|
234
|
+
yield 'Follow-up'
|
|
235
|
+
}
|
|
158
236
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
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('
|
|
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
|
-
|
|
309
|
+
## Server-side Client Access
|
|
197
310
|
|
|
198
311
|
```ts
|
|
199
|
-
export default (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
227
|
-
showURL: false,
|
|
228
|
-
sync: {
|
|
229
|
-
|
|
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
|
-
|
|
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
|
-
-
|
|
278
|
-
-
|
|
279
|
-
|
|
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)
|
|
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
|