A Discord Bot connected to your Pterodactyl API.
1import { REST, Routes } from "discord.js";
2import * as fs from "node:fs";
3import * as path from "node:path";
4import { fileURLToPath } from "url";
5const __filename = fileURLToPath(import.meta.url);
6const __dirname = path.dirname(__filename);
7import { config } from "dotenv";
8config();
9
10(async () => {
11 const commands = [];
12 const commandsPath = path.join(__dirname, "..", "src", "commands");
13 const commandFiles = fs.readdirSync(commandsPath).filter((file) => file.endsWith(".js"));
14 for (const file of commandFiles) {
15 const filePath = path.join(commandsPath, file);
16 const command = await import(filePath);
17 if (command.default?.data && command.default?.execute) {
18 commands.push(command.default.data.toJSON());
19 }
20 }
21 const rest = new REST({ version: "10" }).setToken(process.env.BOT_TOKEN);
22 try {
23 console.log(`Started refreshing ${commands.length} application (/) commands`);
24 const data = await rest.put(
25 Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.GUILD_ID),
26 { body: commands },
27 );
28 console.log(`Successfully reloaded ${data.length} application (/) commands.`);
29 }
30 catch (error) {
31 console.error(error);
32 }
33})();