Conditional deployment slash commands#17
Closed
Ntalcme wants to merge 5 commits into
Closed
Conversation
* feat(types): Add CommandAuthorization & CommandScope #12 * feat(types): add CommandRequirements, CommandValidation and permission types #12 * feat(lib): add command requirements checker #12 * feat(lib): add error container builder and permission error messages #12 * feat(components): add ephemeral option to Container.build() #12 * fix(client): wrap event listeners to handle async execute #12 * fix(handlers): remove unused imports #12 * feat(events): check command requirements before execution #12 * chore(config): add MAIN_GUILD_ID, OWNER_ID and PRIVILEGED_IDS to env.example #12 * Fix name #12
There was a problem hiding this comment.
Pull request overview
This PR introduces a command “requirements” layer (scope + authorization) and applies it at runtime for both slash and new prefix commands, while also updating the deployment script to deploy “main guild only” slash commands differently in production.
Changes:
- Add command requirement types + validation helpers (scope/authorization) and enforce them in interaction/message handlers.
- Add prefix-command infrastructure (registry, loader, message-create event) and a prefix
pingcommand. - Update command deployment to split production deployment into main-guild vs global commands, and update env vars accordingly.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types/command.ts | Adds requirements/permission types and extends SlashCommand/PrefixCommand shapes. |
| src/registries/prefix-registry.ts | Introduces shared prefix command registry keyed by name and aliases. |
| src/lib/errors.ts | Adds helper to build a permissions error container reply. |
| src/lib/components/container.ts | Adds ephemeral option to Container.build(); refines discord.js imports. |
| src/lib/command-requirements.ts | Adds scope/authorization requirement checking utilities. |
| src/lang/ping.ts | Adds “calculating…” message and exports pingDescription. |
| src/lang/index.ts | Exports pingDescription from the language index. |
| src/lang/errors.ts | Adds localized permissions error message builder. |
| src/handlers/slash-handler.ts | Simplifies loader setup (relies on shared base loader). |
| src/handlers/prefix-handler.ts | Adds prefix command loader + runtime type guard + registry population. |
| src/handlers/event-handler.ts | Simplifies loader setup (relies on shared base loader). |
| src/handlers/base-loader.ts | Adds guarded dynamic import with error logging and skip behavior. |
| src/events/message-create.ts | Adds prefix command dispatch + requirements enforcement. |
| src/events/interaction-create.ts | Enforces requirements for slash commands and replies ephemerally on failure. |
| src/deploy-commands.ts | Splits production deploy into main-guild-only vs global commands; renames dev guild env var. |
| src/commands/slash/ping.ts | Uses pingDescription from lang exports. |
| src/commands/prefix/ping.ts | Adds prefix ping implementation using components v2 rendering. |
| src/client/crownutils-client.ts | Enables message intents, loads prefix commands, and wraps event execution in void. |
| .env.example | Updates env var names and adds IDs used for authorization/scope. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+16
to
18
| if (!isProduction && !testGuildId) { | ||
| throw new Error('Missing DISCORD_GUILD_ID for development deployment'); | ||
| } |
Comment on lines
+42
to
+46
| userId === process.env.OWNER_ID | ||
| ? 'owner' | ||
| : process.env.PRIVILEGED_IDS?.split(',').filter(Boolean).includes(userId) | ||
| ? 'privileged' | ||
| : 'public'; |
Comment on lines
+10
to
+13
| const candidate = obj as Record<string, unknown>; | ||
| if (typeof candidate.name !== 'string') { | ||
| return false; | ||
| } |
Comment on lines
+29
to
+34
| prefixCommands.set(command.name, command); | ||
| if (command.aliases) { | ||
| for (const alias of command.aliases) { | ||
| prefixCommands.set(alias, command); | ||
| } | ||
| } |
Comment on lines
+50
to
+52
| this.discord.once(event.name, (...args) => { | ||
| void event.execute(...args); | ||
| }); |
Comment on lines
+54
to
+56
| this.discord.on(event.name, (...args) => { | ||
| void event.execute(...args); | ||
| }); |
Comment on lines
+68
to
+71
| private async loadPrefixCommands(): Promise<void> { | ||
| await loadPrefixCommands(); | ||
| logger.info(`Loaded ${prefixCommands.size} prefix command(s).`); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.