mirror of
https://github.com/DarthKilroy/Spot.git
synced 2025-12-19 18:26:48 +00:00
26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
|
|
import { Collection } from "discord.js";
|
||
|
|
import { client } from "./bot";
|
||
|
|
import path from 'node:path';
|
||
|
|
import fs from "fs"
|
||
|
|
|
||
|
|
export const bindCommands = async () => {
|
||
|
|
client.commands = new Collection();
|
||
|
|
const foldersPath = path.join(__dirname, 'commands');
|
||
|
|
const commandFolders = fs.readdirSync(foldersPath);
|
||
|
|
|
||
|
|
for (const folder of commandFolders) {
|
||
|
|
const commandsPath = path.join(foldersPath, folder);
|
||
|
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.ts'));
|
||
|
|
for (const file of commandFiles) {
|
||
|
|
const filePath = path.join(commandsPath, file);
|
||
|
|
const command = require(filePath);
|
||
|
|
// Set a new item in the Collection with the key as the command name and the value as the exported module
|
||
|
|
if ('data' in command && 'execute' in command) {
|
||
|
|
client.commands.set(command.data.name, command);
|
||
|
|
console.log(`Bound to ${filePath} command`)
|
||
|
|
} else {
|
||
|
|
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|