Skip to content

Commit 1148475

Browse files
authored
Merge pull request #1138 from LEDBrain/fix/command-execution-permissions
fix: do proper command deployment and require NODE_ENV
2 parents d5d09c1 + 9ff25e1 commit 1148475

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/deploy.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,22 @@ export default async () => {
4242
console.log(commands);
4343

4444
// Use this when in development phase
45-
await rest.put(
46-
Routes.applicationGuildCommands(
47-
env.DISCORD_CLIENT_ID,
48-
env.DISCORD_DEV_GUILD_ID
49-
),
50-
{
45+
if (env.NODE_ENV === 'development') {
46+
await rest.put(
47+
Routes.applicationGuildCommands(
48+
env.DISCORD_CLIENT_ID,
49+
env.DISCORD_DEV_GUILD_ID
50+
),
51+
{
52+
body: commands,
53+
}
54+
);
55+
} else if (env.NODE_ENV === 'production') {
56+
if (!client.isReady()) return;
57+
await rest.put(Routes.applicationCommands(client.user.id), {
5158
body: commands,
52-
}
53-
);
54-
55-
// await rest.put(Routes.applicationCommands(client.user.id), {
56-
// body: commands,
57-
// });
59+
});
60+
}
5861

5962
console.log('Successfully reloaded application (/) commands.');
6063
} catch (error) {

src/env.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { createEnv } from '@t3-oss/env-core';
22
import { z } from 'zod';
33

4+
const nodeEnvs = ['production', 'development'] as const;
5+
46
export const env = createEnv({
57
isServer: true,
68
server: {
79
DISCORD_TOKEN: z.string().min(1),
8-
DISCORD_CLIENT_ID: z.string().min(1),
9-
DISCORD_DEV_GUILD_ID: z.string().min(1),
10-
DISCORD_CLIENT_SECRET: z.string().min(1),
10+
DISCORD_CLIENT_ID: z.string(),
11+
DISCORD_DEV_GUILD_ID: z.string(),
12+
DISCORD_CLIENT_SECRET: z.string(),
1113
DISCORD_REDIRECT_URI: z.string().url().min(1),
1214

1315
DISCORD_ADMIN_ID: z.string().min(1),
@@ -26,6 +28,7 @@ export const env = createEnv({
2628
GAME_DE: z.string().url().optional(),
2729
GAME_DE_USERNAME: z.string().min(1),
2830
GAME_DE_PASSWORD: z.string().min(1),
31+
NODE_ENV: z.enum(nodeEnvs),
2932
},
3033
runtimeEnv: {
3134
...process.env,

0 commit comments

Comments
 (0)