-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.ts
56 lines (46 loc) · 1.51 KB
/
deploy.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
import { config as dotenv } from "dotenv";
import { readdirSync } from "fs";
import { join } from "path";
import { ApplicationCommandData } from "discord.js";
dotenv();
if (!process.env.DISCORDTOKEN) throw Error("No token found in environment!");
if (process.env.SKIPDEPLOY) {
console.log("Skipping deploy...");
process.exit();
}
const commands: ApplicationCommandData[] = [];
for (const file of readdirSync(
join(__dirname, "..", "interaction_data"),
).filter(
// Interaction definitions are copied during container build, this must be done manually without Docker
(f) => f.endsWith(".json"),
)) {
const data = require(join(__dirname, "..", "interaction_data", file));
commands.push(data);
}
(async function () {
const currentUserReq = await fetch("https://discord.com/api/v10/users/@me", {
headers: {
authorization: `Bot ${process.env.DISCORDTOKEN}`,
},
});
if (!currentUserReq.ok)
throw new Error(
`Failed to retrieve current application information: ${await currentUserReq.text()}`,
);
const { id } = await currentUserReq.json();
const registerReq = await fetch(
`https://discord.com/api/v10/applications/${id}/commands`,
{
body: JSON.stringify(commands),
headers: {
authorization: `Bot ${process.env.DISCORDTOKEN}`,
"content-type": "application/json",
},
method: "PUT",
},
);
if (!registerReq.ok)
throw new Error(`Failed to register commands: ${await registerReq.text()}`);
console.log("Deployment succeeded");
})();