@Toxic12

Ошибка с Дискорд-ботом?

Выдает такую ошибку
(node:5416) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, scandir 'C:\Users\777\Desktop\discordbot\command'
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5416) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_reje...). (rejection id: 1)
(node:5416) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

app.js
const Discord = require(`discord.js`);
const bot = new Discord.Client();
const fs = require(`promise-fs`);

const config = require (`./config.json`);

bot.commands = new Discord.Collection();
loadCommands().then(count => console.log(`Loaded ${count} commands`));

bot.on(`message`, async (message) => {
    let arr = message.content.split(/\s+/g);
    let args = arr.slice(1);
    let name = arr[0].slice(config.prefix.length);

    if(!message.content.startsWith(config.prefix)) return;
    if(!message.guild) return;
    if(message.author.bot) return;
    
    let cmd = bot.commands.get(name);
    if(cmd) cmd.run(bot, message, args);
});

bot.on(`guildMemberAdd`, async member => {
    bot.logChannel.send(`О Боже кто же это! ${member}!`);
});

bot.on(`guildMemberRemove`, async member => {
    bot.logChannel.send(`${member} Покинул нас`);
});

bot.on(`ready`, async () => {
    console.log(`Logged as ${bot.user.tag}`);
    bot.logChannel = bot.channels.cache.get(`783928263289339926`);
});

bot.login(config.token);

async function loadCommands() {
    let dir = await fs.readdir(`command`);
    let filles = dir.filter(name => name.endsWith(`.js`));

    files.forEach(file => {
        let name = file.split(`.`)[0];
        let  cmd = require(`./commands/${name}`);
        bot.commands.set(name, cmd);
    });

    return bot.commands.size;
}

Ping.js
module.exports.run = async(bot, message, args) => {
    message.reply(`Pong!`);
}
  • Вопрос задан
  • 125 просмотров
Пригласить эксперта
Ответы на вопрос 2
@Azperin
Дилетант
Error: ENOENT: no such file or directory, scandir 'C:\Users\777\Desktop\discordbot\command'

let dir = await fs.readdir(`command`);
Ответ написан
Комментировать
AlmondPark33609
@AlmondPark33609
Занимаюсь кодингом как хобби
Советую изменить ваш код, добавить данный код и убрать async function loadcommands
fs.readdir('./название папки с командами', (err, files) => {
   if (err) throw err
   let jsfile = files.filter(f => f.split('.').pop() == 'js')
   if (jsfile.length <= 0) return console.log('Команды не найдены!')

   console.log(`Загружено ${jsfile.length} команд`)
  jsfile.forEach((f, i) => {
    let props = require(`./название папки с командами/${f}`)
   client.commands.set(props.help.name, props)
  })
})
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы