-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdeploy-commands.ts
More file actions
33 lines (29 loc) · 926 Bytes
/
deploy-commands.ts
File metadata and controls
33 lines (29 loc) · 926 Bytes
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
import fs from "node:fs";
import path from "node:path";
import { REST, Routes } from "discord.js";
import config from "./config.json" with {type: "json"};
const commands: Array<string> = [];
const commandsPath = path.join(import.meta.dirname, "commands");
const commandFiles = fs.readdirSync(commandsPath);
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = (await import(filePath)).default;
if ("data" in command && "execute" in command) {
commands.push(command.data.toJSON());
} else {
console.log(
`The command at ${filePath} is missing a required "data" or "execute" property.`
);
}
}
const rest = new REST().setToken(process.env.TOKEN || "");
export default async function (clientID) {
try {
await rest.put(
Routes.applicationGuildCommands(clientID, config.serverID || ""),
{ body: commands }
);
} catch (error) {
console.error(error);
}
}