Discord.js Не удается прочитать свойство ‘name’

#javascript #node.js #discord.js

#javascript #node.js #discord.js

Вопрос:

может ли кто-нибудь помочь мне исправить эту ошибку? Это наносит мне некоторый критический ущерб.

 const Discord = require('discord.js');
const config = require('./config.json');
const bot = new Discord.Client();
const cooldowns = new Discord.Collection();
const fs = require('fs');
bot.commands = new Discord.Collection();

fs.readdir('./commands/', (err, files) => {
 if (err) console.log(err);

 let jsfile = files.filter((f) => f.split('.').pop() === 'js');
 if (jsfile.length <= 0) {
  console.log('No Commands fonud!');
  return;
 }

 jsfile.forEach((f, i) => {
  let props = require(`./commands/${f}`);
  console.log(`${f} loaded!`);
  bot.commands.set(props.help.name, props);
 });

 fs.readdir('./events/', (error, f) => {
  if (error) console.log(error);
  console.log(`${f.length} Loading events...`);

  f.forEach((f) => {
   const events = require(`./events/${f}`);
   const event = f.split('.')[0];

   client.on(event, events.bind(null, client));
  });
 });
});

let statuses = ['By LeRegedit#1281', 'Prefix => !', 'V1.0', 'Coming Soon'];

bot.on('ready', () => {
 console.log(bot.user.username   ' is online !');

 setInterval(function() {
  let status = statuses[Math.floor(Math.random() * statuses.length)];
  bot.user.setPresence({ activity: { name: status }, status: 'online' });
 }, 10000);
});

bot.on('message', async (message) => {
 if (message.author.bot) return;
 if (message.channel.type === 'dm') return;
 let content = message.content.split(' ');
 let command = content[0];
 let args = content.slice(1);
 let prefix = config.prefix;
 let commandfile = bot.commands.get(command.slice(prefix.length));
 if (commandfile) commandfile.run(bot, message, args);
 if (!message.content.startsWith(prefix)) return;
});

bot.login(config.token);
  

Ошибка типа: не удается прочитать свойство ‘name’ неопределенного

Комментарии:

1. Первым шагом отладки является распечатка переменных в вашей консоли, чтобы увидеть, какие данные установлены для вашей переменной, которая вызывает проблемы. В этом случае проверьте это, распечатав props и props.help .

2. Это полная ошибка: TypeError: не удается прочитать свойство ‘name’ неопределенного в c:UsersLeRegeditDesktopDragoniteindex.js:21:31 в Array.forEach (<анонимный>) в c:UsersLeRegeditDesktopDragoniteindex.js:18:8 при FSReqCallback.oncomplete (fs.js:156:23) при FSReqCallback.callbackTrampoline (internal/ async_hooks.js:120:14) Процесс завершается с кодом 1

3. Ваш код перестал работать в at Array.forEach on line 21 . Выполните console.log(props) . Какие ошибки вы получаете? Если нет, переходите к следующему шагу: console.log(props.help)

4. Я даже не могу его загрузить, вот почему это важно. Также это появляется, когда я пытаюсь запустить: ожидание отключения отладчика … c:UsersLeRegeditDesktopDragoniteindex.js:21 bot.commands.set(props.help.name , реквизит);

5. Я думаю, что исправил это, спасибо за вашу помощь! Это «.name» в модуле, который вызвал все это!