A discord bot for teal.fm
discord
tealfm
music
1import { REST, Routes } from "discord.js";
2import fs from "node:fs";
3import path from "node:path";
4import {
5 DISCORD_APPLICATION_ID,
6 DISCORD_BOT_TOKEN,
7 DISCORD_GUILD_ID,
8} from "./constants.ts";
9
10const commands = [];
11const commandPaths = fs.globSync("commands/**/*.ts");
12
13for await (const cmdPath of commandPaths) {
14 const absoluteCommandPath = path.join(import.meta.dirname, cmdPath)
15 const command = await import(absoluteCommandPath)
16 if ("data" in command.default && "execute" in command.default) {
17 commands.push(command.default.data);
18 } else {
19 console.warn(
20 `[Warning] The command at ${absoluteCommandPath} is missing a required "data" or "execute" property.`,
21 );
22 }
23}
24
25const rest = new REST().setToken(DISCORD_BOT_TOKEN);
26
27(async () => {
28 try {
29 console.log(
30 `Started refreshing ${commands.length} application (/) commands.`,
31 );
32
33 const data = await rest.put(
34 Routes.applicationGuildCommands(DISCORD_APPLICATION_ID, DISCORD_GUILD_ID),
35 { body: commands },
36 ) as unknown[];
37
38 console.log(
39 `Successfully reloaded ${data.length} application (/) commands.`,
40 );
41 } catch (error) {
42 console.error(error);
43 }
44})();