First Upload
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const config = require("../configs/config.json");
|
||||
const { REST, Routes } = require('discord.js');
|
||||
|
||||
// Replace with your bot's token and client ID
|
||||
const TOKEN = config.token;
|
||||
const CLIENT_ID = config.clientId;
|
||||
|
||||
async function registerCommands() {
|
||||
const commands = [];
|
||||
const commandsPath = path.join(__dirname, '../commands');
|
||||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||
|
||||
// Dynamically read all command files
|
||||
for (const file of commandFiles) {
|
||||
const command = require(path.join(commandsPath, file));
|
||||
if (command.name && command.description) {
|
||||
commands.push({
|
||||
name: command.name,
|
||||
description: command.description,
|
||||
options: command.options || [] // Add options if your commands have them
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Register commands with Discord API
|
||||
const rest = new REST({ version: '10' }).setToken(TOKEN);
|
||||
|
||||
try {
|
||||
console.log('Started refreshing application (/) commands.');
|
||||
|
||||
// Register commands globally (for all servers)
|
||||
await rest.put(
|
||||
Routes.applicationCommands(CLIENT_ID),
|
||||
{ body: commands }
|
||||
);
|
||||
|
||||
console.log('Successfully reloaded application (/) commands.');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { registerCommands };
|
||||
Reference in New Issue
Block a user