blob: a9a5deb3cbd1cafc14b80e8e949b100040093e60 (
plain) (
blame)
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
|
import { HOT_COMMAND, ROLEPLAY_COMMAND } from './commands.js';
import dotenv from 'dotenv';
import process from 'node:process';
dotenv.config({ path: '.dev.vars' });
const token = process.env.DISCORD_TOKEN;
const applicationID = process.env.DISCORD_APPLICATION_ID;
if (!token)
throw new Error('The DISCORD_TOKEN environment variable is required.');
if (!applicationID)
throw new Error(
'The DISCORD_APPLICATION_ID environment variable is required.',
);
const url = `https://discord.com/api/v10/applications/${applicationID}/commands`;
const response = await fetch(url, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bot ${token}`,
},
method: 'PUT',
body: JSON.stringify([HOT_COMMAND, ROLEPLAY_COMMAND]),
});
if (response.ok) {
console.log('Registered all commands');
const data = await response.json();
console.log(JSON.stringify(data, null, 2));
} else {
console.error('Error registering commands');
let errorText = `Error registering commands \n ${response.url}: ${response.status} ${response.statusText}`;
try {
const error = await response.text();
if (error) errorText = `${errorText} \n\n ${error}`;
} catch (error) {
console.error('Error reading body from request:', error);
}
console.error(errorText);
}
|