Деплой "/" команд discord.js
Всем привет! Не могу понять почему при деплое слеш команд для бота в дискорде вылетает ошибка:
Error: Cannot find module './commands/ping2.js'
code: 'MODULE_NOT_FOUND', requireStack: [ 'C:\\Users\\бур\\Desktop\\penis3-main\\deployment_slash.js' ]
Команды размещены в подпапках папки commands. Если разместить команды вне подпапок а просто в commands всё работает.
Ниже файл деплоя, закоментированная строчка была изначально и может прочитать команды только вне подпапок.
const { REST, Routes } = require('discord.js');
const dotenv = require('dotenv');
const { dir } = require('node:console');
const fs = require('node:fs');
dotenv.config();
const commands = [];
let commandFiles = []
fs.readdirSync("./commands").forEach(dir => fs.readdirSync(`./commands/${dir}`)
.forEach(file_ => {
commandFiles.push(file_)
}));
console.log(commandFiles)
//const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '10' }).setToken(process.env.token);
(async () => {
try {
console.log(`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.applicationGuildCommands(process.env.clientId, process.env.guildId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();