38 lines
1,004 B
JavaScript
38 lines
1,004 B
JavaScript
|
import { REST } from '@discordjs/rest';
|
||
|
import { Routes } from 'discord-api-types/v9';
|
||
|
import { readdir } from 'fs/promises';
|
||
|
|
||
|
export default async client => {
|
||
|
const rest = new REST({ version: '9' }).setToken(client.token);
|
||
|
|
||
|
const command_categories = (await readdir('./src/commands'))
|
||
|
.filter(element => !element.endsWith('.js'));
|
||
|
|
||
|
const commands = (
|
||
|
await Promise.all(
|
||
|
// For each categorie
|
||
|
command_categories.map(async command_category => {
|
||
|
// Retrieve all the commands
|
||
|
const command_files = await readdir(`./src/commands/${command_category}`);
|
||
|
|
||
|
// Add the command
|
||
|
return Promise.all(
|
||
|
command_files.map(async command_file => {
|
||
|
const command = (
|
||
|
await import(`../commands/${command_category}/${command_file}`)
|
||
|
).default;
|
||
|
|
||
|
client.commands.set(command.data.name, command);
|
||
|
|
||
|
return command.data.toJSON();
|
||
|
}),
|
||
|
);
|
||
|
}),
|
||
|
)
|
||
|
).flat(2);
|
||
|
|
||
|
return await rest.put(Routes.applicationCommands(client.user.id), {
|
||
|
body: commands,
|
||
|
});
|
||
|
};
|