-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy-commands.ts
74 lines (64 loc) · 2.08 KB
/
deploy-commands.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {
SlashCommandBuilder,
SlashCommandStringOption,
SlashCommandSubcommandBuilder,
Routes,
REST
} from "discord.js";
import dotenv from "dotenv";
dotenv.config();
// Load DISCORD_TOKEN from environment variables and throw an error if it's not set
let discordToken = process.env.DISCORD_TOKEN;
if (discordToken == null) {
throw new Error("DISCORD_TOKEN environment variable not set");
}
// Load GUILD_ID from environment variables and throw an error if it's not set
let guildId = process.env.GUILD_ID;
if (guildId == null) {
throw new Error("GUILD_ID environment variable not set");
}
// Load CLIENT_ID from environment variables and throw an error if it's not set
let clientId = process.env.CLIENT_ID;
if (clientId == null) {
throw new Error("CLIENT_ID environment variable not set");
}
const commands = [
new SlashCommandBuilder()
.setName("horaires")
.setDescription("Horaires en direct pour la CTS")
.setDescription(
"Affiche les horaires pour n'importe quelle station (données CTS)"
)
.addStringOption(
new SlashCommandStringOption()
.setName("station")
.setDescription("Station à rechercher et afficher")
.setRequired(true)
),
new SlashCommandBuilder()
.setName("sources")
.setDescription(
"Affiche les sources des données du robot et les avertissements de fiabilité"
),
].map((command) => command.toJSON());
const rest = new REST({ version: "9" }).setToken(discordToken);
(async () => {
try {
await rest.put(Routes.applicationCommands(clientId), {
body: commands,
});
console.log("Successfully registered global application commands.");
} catch (error) {
console.error(error);
}
})();
(async () => {
try {
await rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: [],
});
console.log("Successfully registered application commands.");
} catch (error) {
console.error(error);
}
})();