NodeJS - TypeError: Cannot read property 'name' of undefined












0















I am getting the following error from my code: If you could help me that would be amazing! I am using discord.js!






TypeError: Cannot read property 'name' of undefined at
files.forEach.file (/root/eternity-bot/eternity-bot/index.js:21:33) at
Array.forEach () at fs.readdir
(/root/eternity-bot/eternity-bot/index.js:18:9) at
FSReqWrap.oncomplete (fs.js:135:15)






fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
console.log(`Loading Command: ${props.help.name}.`);
bot.commands.set(props.help.name, props);
props.conf.aliases.forEach(alias => {
bot.aliases.set(alias, props.help.name);
})
});
});









share|improve this question

























  • Please paste the contents of the js file in the commands folder.

    – Rohan Dhar
    Nov 26 '18 at 3:12











  • What is props retuning? it does not have help tag .... let props = require(./commands/${file}); console.log(Loading Command: ${props.help.name}.);

    – Naveen Ramawat
    Nov 26 '18 at 6:31













  • Either you are not importing the props file, or the help property does not exist.

    – mjrcodin
    Nov 26 '18 at 7:06
















0















I am getting the following error from my code: If you could help me that would be amazing! I am using discord.js!






TypeError: Cannot read property 'name' of undefined at
files.forEach.file (/root/eternity-bot/eternity-bot/index.js:21:33) at
Array.forEach () at fs.readdir
(/root/eternity-bot/eternity-bot/index.js:18:9) at
FSReqWrap.oncomplete (fs.js:135:15)






fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
console.log(`Loading Command: ${props.help.name}.`);
bot.commands.set(props.help.name, props);
props.conf.aliases.forEach(alias => {
bot.aliases.set(alias, props.help.name);
})
});
});









share|improve this question

























  • Please paste the contents of the js file in the commands folder.

    – Rohan Dhar
    Nov 26 '18 at 3:12











  • What is props retuning? it does not have help tag .... let props = require(./commands/${file}); console.log(Loading Command: ${props.help.name}.);

    – Naveen Ramawat
    Nov 26 '18 at 6:31













  • Either you are not importing the props file, or the help property does not exist.

    – mjrcodin
    Nov 26 '18 at 7:06














0












0








0








I am getting the following error from my code: If you could help me that would be amazing! I am using discord.js!






TypeError: Cannot read property 'name' of undefined at
files.forEach.file (/root/eternity-bot/eternity-bot/index.js:21:33) at
Array.forEach () at fs.readdir
(/root/eternity-bot/eternity-bot/index.js:18:9) at
FSReqWrap.oncomplete (fs.js:135:15)






fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
console.log(`Loading Command: ${props.help.name}.`);
bot.commands.set(props.help.name, props);
props.conf.aliases.forEach(alias => {
bot.aliases.set(alias, props.help.name);
})
});
});









share|improve this question
















I am getting the following error from my code: If you could help me that would be amazing! I am using discord.js!






TypeError: Cannot read property 'name' of undefined at
files.forEach.file (/root/eternity-bot/eternity-bot/index.js:21:33) at
Array.forEach () at fs.readdir
(/root/eternity-bot/eternity-bot/index.js:18:9) at
FSReqWrap.oncomplete (fs.js:135:15)






fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
console.log(`Loading Command: ${props.help.name}.`);
bot.commands.set(props.help.name, props);
props.conf.aliases.forEach(alias => {
bot.aliases.set(alias, props.help.name);
})
});
});






node.js discord.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 6:57









SakoBu

1,751521




1,751521










asked Nov 26 '18 at 1:57









Mark DavidMark David

52




52













  • Please paste the contents of the js file in the commands folder.

    – Rohan Dhar
    Nov 26 '18 at 3:12











  • What is props retuning? it does not have help tag .... let props = require(./commands/${file}); console.log(Loading Command: ${props.help.name}.);

    – Naveen Ramawat
    Nov 26 '18 at 6:31













  • Either you are not importing the props file, or the help property does not exist.

    – mjrcodin
    Nov 26 '18 at 7:06



















  • Please paste the contents of the js file in the commands folder.

    – Rohan Dhar
    Nov 26 '18 at 3:12











  • What is props retuning? it does not have help tag .... let props = require(./commands/${file}); console.log(Loading Command: ${props.help.name}.);

    – Naveen Ramawat
    Nov 26 '18 at 6:31













  • Either you are not importing the props file, or the help property does not exist.

    – mjrcodin
    Nov 26 '18 at 7:06

















Please paste the contents of the js file in the commands folder.

– Rohan Dhar
Nov 26 '18 at 3:12





Please paste the contents of the js file in the commands folder.

– Rohan Dhar
Nov 26 '18 at 3:12













What is props retuning? it does not have help tag .... let props = require(./commands/${file}); console.log(Loading Command: ${props.help.name}.);

– Naveen Ramawat
Nov 26 '18 at 6:31







What is props retuning? it does not have help tag .... let props = require(./commands/${file}); console.log(Loading Command: ${props.help.name}.);

– Naveen Ramawat
Nov 26 '18 at 6:31















Either you are not importing the props file, or the help property does not exist.

– mjrcodin
Nov 26 '18 at 7:06





Either you are not importing the props file, or the help property does not exist.

– mjrcodin
Nov 26 '18 at 7:06












2 Answers
2






active

oldest

votes


















2














TypeError: A TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or function.



The possible cause is your props is not loaded correctly and doesn't include any property help, thus accessing property name of unknown property help throws TypeError. Similar to following:



let obj = {
o1: {
a: 'abc'
}
};

obj.o1 // gives {a: 'abc'}, as o1 is property obj which is an object.
obj.o1.a // gives 'abc', as a is property of o1, which is property of obj.
obj.o2 // undefined, as there's no o2 property in obj.
obj.o2.a // TypeError as there's no o2 property of obj and thus accessing property a of undefined gives error.





share|improve this answer































    1














    What is happening is that the code is working perfectly fine, but there seems to be some problem with the exports of your javascript files in the commands folder. Most probably, the help property is not defined in your files.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473858%2fnodejs-typeerror-cannot-read-property-name-of-undefined%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      TypeError: A TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or function.



      The possible cause is your props is not loaded correctly and doesn't include any property help, thus accessing property name of unknown property help throws TypeError. Similar to following:



      let obj = {
      o1: {
      a: 'abc'
      }
      };

      obj.o1 // gives {a: 'abc'}, as o1 is property obj which is an object.
      obj.o1.a // gives 'abc', as a is property of o1, which is property of obj.
      obj.o2 // undefined, as there's no o2 property in obj.
      obj.o2.a // TypeError as there's no o2 property of obj and thus accessing property a of undefined gives error.





      share|improve this answer




























        2














        TypeError: A TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or function.



        The possible cause is your props is not loaded correctly and doesn't include any property help, thus accessing property name of unknown property help throws TypeError. Similar to following:



        let obj = {
        o1: {
        a: 'abc'
        }
        };

        obj.o1 // gives {a: 'abc'}, as o1 is property obj which is an object.
        obj.o1.a // gives 'abc', as a is property of o1, which is property of obj.
        obj.o2 // undefined, as there's no o2 property in obj.
        obj.o2.a // TypeError as there's no o2 property of obj and thus accessing property a of undefined gives error.





        share|improve this answer


























          2












          2








          2







          TypeError: A TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or function.



          The possible cause is your props is not loaded correctly and doesn't include any property help, thus accessing property name of unknown property help throws TypeError. Similar to following:



          let obj = {
          o1: {
          a: 'abc'
          }
          };

          obj.o1 // gives {a: 'abc'}, as o1 is property obj which is an object.
          obj.o1.a // gives 'abc', as a is property of o1, which is property of obj.
          obj.o2 // undefined, as there's no o2 property in obj.
          obj.o2.a // TypeError as there's no o2 property of obj and thus accessing property a of undefined gives error.





          share|improve this answer













          TypeError: A TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or function.



          The possible cause is your props is not loaded correctly and doesn't include any property help, thus accessing property name of unknown property help throws TypeError. Similar to following:



          let obj = {
          o1: {
          a: 'abc'
          }
          };

          obj.o1 // gives {a: 'abc'}, as o1 is property obj which is an object.
          obj.o1.a // gives 'abc', as a is property of o1, which is property of obj.
          obj.o2 // undefined, as there's no o2 property in obj.
          obj.o2.a // TypeError as there's no o2 property of obj and thus accessing property a of undefined gives error.






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 26 '18 at 19:19









          NAVINNAVIN

          1,6793725




          1,6793725

























              1














              What is happening is that the code is working perfectly fine, but there seems to be some problem with the exports of your javascript files in the commands folder. Most probably, the help property is not defined in your files.






              share|improve this answer




























                1














                What is happening is that the code is working perfectly fine, but there seems to be some problem with the exports of your javascript files in the commands folder. Most probably, the help property is not defined in your files.






                share|improve this answer


























                  1












                  1








                  1







                  What is happening is that the code is working perfectly fine, but there seems to be some problem with the exports of your javascript files in the commands folder. Most probably, the help property is not defined in your files.






                  share|improve this answer













                  What is happening is that the code is working perfectly fine, but there seems to be some problem with the exports of your javascript files in the commands folder. Most probably, the help property is not defined in your files.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 26 '18 at 8:59









                  Rohan DharRohan Dhar

                  1,1451418




                  1,1451418






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473858%2fnodejs-typeerror-cannot-read-property-name-of-undefined%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Wiesbaden

                      Marschland

                      Dieringhausen