-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.ts
77 lines (73 loc) · 1.73 KB
/
register.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
75
76
77
import "$std/dotenv/load.ts";
const COMMANDS = [
{
type: 1,
name: "hello",
description: "Says hi back!",
dm_permission: false,
nsfw: false,
},
{
type: 1,
name: "create",
description: "Create a giveaway!",
dm_permission: false,
"options": [
{
type: 3,
name: "prize",
description:
"The prize of the giveaway (supports markdown syntax highlighting)",
required: true,
},
{
type: 3,
name: "duration",
description: "The relative duration of the giveaway such as 1h 20m",
required: true,
},
{
type: 3,
name: "message",
description: "A place to put conditions, terms, FAQs",
required: true,
},
{
type: 3,
name: "image",
description: "A URL to the image to be shown (changes the embed color)",
},
{
type: 4,
name: "winners",
description: "The amount of winners, defaults to 1",
},
],
nsfw: false,
},
];
if (!import.meta.main) {
console.log("This module is not meant to be imported.");
Deno.exit(1);
}
await COMMANDS.reduce(async (prms, cmd) => {
await prms;
const response = await fetch(
`https://discord.com/api/v10/applications/${
Deno.env.get("CLIENT_ID")
}/commands`,
{
method: "POST",
headers: {
Authorization: `Bot ${Deno.env.get("BOT_TOKEN")}`,
"Content-Type": "application/json",
},
body: JSON.stringify(cmd),
},
);
if (!response.ok) {
return console.error(await response.json());
}
console.log(`successfully registered ${cmd.name}.`);
await new Promise((resolve) => setTimeout(resolve, 1e3));
}, Promise.resolve());