-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetupCommands.js
81 lines (69 loc) · 1.92 KB
/
setupCommands.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
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
78
79
80
81
import Logging from "./lib/Logging.js";
// should all commands be deleted before being registered
const DELETE_BEFORE = false;
// Commands to be defined
const COMMANDS = [
{
name: "ping",
description: "Replies with Pong!",
},
{
name: "reinstall",
description: "Reinstall the SCP:SL server.",
},
{
name: "restart",
description: "Restart the SCP:SL server.",
},
{
name: "start",
description: "Start the SCP:SL server.",
},
{
name: "stop",
description: "Stop the SCP:SL server.",
},
{
name: "playerlist",
description: "Get a list of players on the SCP:SL server.",
},
];
import { REST, Routes } from "discord.js";
import dotenv from "dotenv";
dotenv.config();
if (!process.env.DISCORD_TOKEN) {
Logging.logCritical(
"Could not register discord commands since no token was found!"
);
process.exit();
}
const TOKEN = process.env.DISCORD_TOKEN;
const CLIENT_ID = process.env.CLIENT_ID;
const GUILD_ID = process.env.GUILD_ID;
const rest = new REST({ version: "10" }).setToken(TOKEN);
try {
if (DELETE_BEFORE) await deleteAllCommands();
await registerAllCommands();
} catch (error) {
Logging.logError("Failed to delete all commands: " + error);
}
async function deleteAllCommands() {
await rest
.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: [] })
.then(() => console.log("Successfully deleted all guild commands."))
.catch(console.error);
// for global commands
await rest
.put(Routes.applicationCommands(CLIENT_ID), { body: [] })
.then(() =>
Logging.logInfo("Successfully deleted all application commands.")
)
.catch(console.error);
}
async function registerAllCommands() {
Logging.logInfo("Started refreshing application (/) commands.");
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), {
body: COMMANDS,
});
Logging.logInfo("Successfully reloaded application (/) commands.");
}