-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployCommands.js
41 lines (36 loc) · 1.16 KB
/
deployCommands.js
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
import { DISCORD_APP_USER_ID, DISCORD_TOKEN } from './config.js';
// SLASH COMMANDS
import * as CoinCommand from './Commands/SlashCommands/General/coin.js';
/** URL used to register Interaction Commands */
const url = `https://discord.com/api/v10/applications/${DISCORD_APP_USER_ID}/commands`;
/** Array of Commands to register */
const CommandArray = [
CoinCommand.SlashCommand.getRegisterData()
];
const response = await fetch(url, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bot ${DISCORD_TOKEN}`
},
method: 'PUT',
body: JSON.stringify(CommandArray)
});
if ( response.ok ) {
console.log(`Deployed!`);
const data = await response.json();
console.log(JSON.stringify(data, null, 2));
}
else {
console.error(`Error deploying`);
let errorText = `Error deploying commands. \n ${response.url}: ${response.status} ${response.statusText}`;
try {
const error = await response.text();
if ( error ) {
errorText = `${errorText} \n\n ${error}`;
}
}
catch (err) {
console.error(`Error reading body from request:`, err);
}
console.error(errorText);
}