Skip to content

Commit 704e00e

Browse files
luca-montaigutpotb
authored andcommitted
fix: remove useless env variables (#72)
1 parent f18bc8d commit 704e00e

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

.env.example

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# SETUP
22
DISCORD_TOKEN=
3-
DISCORD_CLIENT_ID=
4-
DISCORD_GUILD_ID=
53

64
# DB
75
REDIS_URL=
86

97
# CHANNELS
10-
BLABLA_CHANNEL_ID=
118
COOL_LINKS_CHANNEL_ID=
129

1310
# API

src/config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import env from 'env-var';
33
export const config = {
44
discord: {
55
token: env.get('DISCORD_TOKEN').required().asString(),
6-
clientId: env.get('DISCORD_CLIENT_ID').required().asString(),
7-
guildId: env.get('DISCORD_GUILD_ID').required().asString(),
86
coolLinksChannelId: env.get('COOL_LINKS_CHANNEL_ID').required().asString(),
97
},
108
redis: {

src/core/deleteExistingCommands.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { REST, Routes } from 'discord.js';
22

3-
import { config } from '../config';
4-
53
export const deleteExistingCommands = async (
64
rest: REST,
7-
discord: typeof config.discord,
5+
clientId: string,
6+
guildId: string,
87
): Promise<void> => {
9-
const guildCommands = (await rest.get(
10-
Routes.applicationGuildCommands(discord.clientId, discord.guildId),
11-
)) as { id: string }[];
8+
const guildCommands = (await rest.get(Routes.applicationGuildCommands(clientId, guildId))) as {
9+
id: string;
10+
}[];
1211

1312
await guildCommands.reduce<Promise<void>>(async (promise, guildCommand) => {
1413
await promise;
1514

16-
await rest.delete(
17-
Routes.applicationGuildCommand(discord.clientId, discord.guildId, guildCommand.id),
18-
);
15+
await rest.delete(Routes.applicationGuildCommand(clientId, guildId, guildCommand.id));
1916
}, Promise.resolve());
2017
};

src/core/loadModules.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ export const loadModules = async (
1212
const botCommands = Object.values(modulesToLoad).flatMap((module) => module.slashCommands ?? []);
1313
checkUniqueSlashCommandNames(botCommands);
1414
routeCommands(client, botCommands);
15-
await pushCommands(botCommands.map((command) => command.schema));
1615

16+
const clientId = client.application?.id;
17+
if (!clientId) throw new Error('Client id is not defined');
18+
19+
const { guilds } = client;
20+
21+
for (const guild of guilds.cache.values()) {
22+
await pushCommands(
23+
botCommands.map((command) => command.schema),
24+
clientId,
25+
guild.id,
26+
);
27+
}
1728
routeHandlers(client, modulesToLoad);
1829
};

src/core/loaderCommands.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ import { deleteExistingCommands } from './deleteExistingCommands';
1111

1212
const { discord } = config;
1313

14-
export const pushCommands = async (commands: RESTPostAPIChatInputApplicationCommandsJSONBody[]) => {
14+
export const pushCommands = async (
15+
commands: RESTPostAPIChatInputApplicationCommandsJSONBody[],
16+
clientId: string,
17+
guildId: string,
18+
) => {
1519
const rest = new REST({ version: '10' }).setToken(discord.token);
16-
await deleteExistingCommands(rest, discord);
17-
await rest.put(Routes.applicationGuildCommands(discord.clientId, discord.guildId), {
20+
await deleteExistingCommands(rest, clientId, guildId);
21+
await rest.put(Routes.applicationGuildCommands(clientId, guildId), {
1822
body: commands,
1923
});
2024
};

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { modules } from './modules/modules';
88
const { discord } = config;
99

1010
const client = new Client({
11-
intents: getIntentsFromModules(modules),
11+
intents: ['Guilds', ...getIntentsFromModules(modules)],
1212
});
1313

1414
await client.login(discord.token);

0 commit comments

Comments
 (0)