-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.js
More file actions
58 lines (48 loc) · 1.92 KB
/
Copy pathdeploy.js
File metadata and controls
58 lines (48 loc) · 1.92 KB
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
/**
* @file Deploys commands to discord API
*/
import fs from "fs";
import path from "path";
import { REST, Routes } from "discord.js";
import { slashCommand, messageCommand, userCommand } from "./server/sandra.js";
import { votedCommand } from "./server/voted.js";
import "dotenv/config";
const __dirname = import.meta.dirname;
const commands = [];
const foldersPath = path.join(__dirname, "commands");
const commandfolders = fs.readdirSync(foldersPath);
for (const folder of commandfolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".js"));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const { data } = await import("file://" + filePath);
if (data) {
commands.push(data.toJSON());
} else {
console.log(`[WARN] The command at ${filePath} is missing required "data" property.`);
}
}
}
const rest = new REST().setToken(process.env.DISCORD_TOKEN);
try {
console.log("Started refreshing application (/) commands.");
for (let command of commands) {
if (command.name === "candidates" || command.name === "constituency" || command.name === "results") {
command.integration_types = [0, 1];
}
}
await rest.put(
Routes.applicationCommands(process.env.DISCORD_CLIENT_ID),
{ body: commands },
);
console.log("Started refreshing application guild (/guild) commands.");
await rest.put(
Routes.applicationGuildCommands(process.env.DISCORD_CLIENT_ID, process.env.DISCORD_GUILD_ID),
{ body: [slashCommand.toJSON(), messageCommand.toJSON(), userCommand.toJSON(), votedCommand.toJSON()] },
);
console.log("Successfully reloaded application (/) commands.");
} catch (err) {
console.error(err);
console.error("Failed to reload application (/) commands.");
}