Skip to content

Commit 07397ff

Browse files
authored
Merge pull request #165 from cainthebest/fix/add-guard-for-dev-mode
Fix: add guard for dev mode
2 parents 6cd717c + 0c136ba commit 07397ff

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

.changeset/rich-bugs-tickle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'jellycommands': patch
3+
---
4+
5+
add a guard to catch no guild id when dev mode enabled

docs/guide/commands/dev.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const client = new JellyCommands({
1818

1919
For additional options, see [dev options](/api/client#dev).
2020

21+
:::tip NOTE
22+
If `dev` mode is enabled, at least one guild id must be specified within [`dev.guilds`](/api/client#dev)
23+
:::
24+
2125
## Global Dev Mode
2226

2327
Adding `dev: true` to every command *(and remembering to remove it)* can be tedious. [global dev mode](/api/client#dev-global) makes this easier.

packages/jellycommands/src/JellyCommands.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ export class JellyCommands extends Client {
5151
if (this.joptions.commands) {
5252
const commands = await resolveCommands(this, this.joptions.commands);
5353
const commandIdMap = await getCommandIdMap(this, commands);
54+
if (!this.joptions.dev?.guilds?.length) {
55+
const hasDevCommand = Array.from(commands.commands).some(
56+
(command) => command.options.dev,
57+
);
58+
59+
// If dev is enabled in some way, make sure they have at least one guild id
60+
if (this.joptions.dev?.global || hasDevCommand)
61+
throw new Error(
62+
'You must provide at least one guild id in the dev guilds array to use dev commands',
63+
);
64+
}
5465

5566
// Whenever there is a interactionCreate event respond to it
5667
this.on('interactionCreate', (interaction) => {

0 commit comments

Comments
 (0)