DiscordJS-Template/deploy.js

39 lines
1.3 KiB
JavaScript
Raw Normal View History

import { getFiles, importAndCheck } from './shared.js';
2024-01-13 16:05:16 +00:00
import { REST, Routes } from 'discord.js';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { config } from 'dotenv';
config();
// Construct and prepare an instance of the REST module
const rest = new REST().setToken(process.env.TOKEN);
// and deploy your commands!
const putCommands = async (commands) => {
try {
console.info(`[INFO] Started refreshing ${commands.length} application (/) commands.`);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(Routes.applicationCommands(process.env.CLIENT), { body: commands });
console.info(`[INFO] Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error('[ERROR] Uncaught error:');
console.error(error);
}
};
// Register commands from sub-directories
const __dirname = dirname(fileURLToPath(import.meta.url));
const cmdPath = join(__dirname, 'commands');
getFiles(cmdPath)
// For each command file
.then(async (files) =>
(await Promise.all(files.map(importAndCheck)))
.filter((module) => module !== 0)
.map((module) => module.data.toJSON())
2024-02-06 15:18:06 +00:00
)
.then(putCommands);