-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy_commands.js
More file actions
27 lines (24 loc) · 1.03 KB
/
Copy pathdeploy_commands.js
File metadata and controls
27 lines (24 loc) · 1.03 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
import 'dotenv/config';
import { REST, Routes } from 'discord.js';
import fs from 'fs/promises';
import path from 'path';
import logger from '#utils/logger.js';
const { DISCORD_TOKEN, CLIENT_ID, GUILD_ID } = process.env;
const commands = [];
const baseDir = import.meta.dirname;
const commandFiles = await fs.opendir(path.join(baseDir, './src/commands'), { recursive: true });
for await (const commandFile of commandFiles) {
if (commandFile.isFile() && commandFile.name.endsWith('.js')) {
const relativeFile = `./${path.relative(baseDir, commandFile.parentPath)}/${commandFile.name}`;
const command = await import(relativeFile);
commands.push(command.data.toJSON());
logger.info(`Loaded command: ${command.data.name} from ${relativeFile}`);
}
}
const rest = new REST().setToken(DISCORD_TOKEN);
const data = await rest.put(
// Remove guild id to register global commands
Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID),
{ body: commands }
);
logger.info(`Successfully reloaded ${data.length} application (/) commands.`);