cur10s
DIAdiscord.js - Imagine an app
•Created by cur10s on 3/3/2024 in #djs-questions
Package path error
ow that works ! thank you very much 😄
5 replies
DIAdiscord.js - Imagine an app
•Created by cur10s on 3/3/2024 in #djs-questions
Package path error
handleCommands :
Any help would be great, as i'm pretty new to discord.js and js in general ://
const { REST } = require("@discordjs/rest");
const { Routes } = require('discord-api-types')
const fs = require("fs");
module.exports = (client) => {
client.handleCommands = async () => {
const commandFolders = fs.readdirSync("./src/commands");
for (const folder of commandFolders) {
const commandFiles = fs
.readdirSync(`./src/commands/${folder}`)
.filter((file) => file.endsWith(".js"));
const { commands, commandArray } = client;
for (const file of commandFiles) {
const command = require(`../../commands/${folder}/${file}`);
commands.set(command.data.name, command);
commandArray.push(command.data.toJSON());
console.log(
`Command : ${command.data.name} has been passed through the handler`
);
}
}
const clientId = "1213782624443834388";
const guildId = "1213484196572569600";
const rest = new REST({ version: "9" }).setToken(process.env.token);
try {
console.log("Started refreshing applications (/) commands.");
await rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: client.commandArray,
});
console.log("Succesfully reloaded application (/) commands.");
} catch (error) {
console.error(error);
}
};
};
const { REST } = require("@discordjs/rest");
const { Routes } = require('discord-api-types')
const fs = require("fs");
module.exports = (client) => {
client.handleCommands = async () => {
const commandFolders = fs.readdirSync("./src/commands");
for (const folder of commandFolders) {
const commandFiles = fs
.readdirSync(`./src/commands/${folder}`)
.filter((file) => file.endsWith(".js"));
const { commands, commandArray } = client;
for (const file of commandFiles) {
const command = require(`../../commands/${folder}/${file}`);
commands.set(command.data.name, command);
commandArray.push(command.data.toJSON());
console.log(
`Command : ${command.data.name} has been passed through the handler`
);
}
}
const clientId = "1213782624443834388";
const guildId = "1213484196572569600";
const rest = new REST({ version: "9" }).setToken(process.env.token);
try {
console.log("Started refreshing applications (/) commands.");
await rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: client.commandArray,
});
console.log("Succesfully reloaded application (/) commands.");
} catch (error) {
console.error(error);
}
};
};
5 replies