#require(. . .) is not a function

9 messages · Page 1 of 1 (latest)

solar gazelleBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

midnight phoenix
#

are you exporting a function?

wind depot
#

classic brain dead mistake

#

i typed module.export instead of module.exports

midnight phoenix
#

it happens

wind depot
#

but i got another error now

#

this is the handleComponents:

const { readdirSync } = require("fs");

module.exports = (client) => {
  client.handleComponents = async () => {
    const componentFolders = readdirSync(`./src/components`);
    for (const folder of componentFolders) {
      const componentFiles = readdirSync(`./src/components/${folder}`).filter(
        (file) => file.endsWith(".js")
      );
    }

    const { buttons } = client;

    switch (folder) {
      case "buttons":
        for (const file of componentFiles) {
          const button = require(`../../components/${folder}/${file}`);
          buttons.set(button.data.name, button);
        }
        break;

      default:
        break;
    }
  };
};
#

says this:

#

switch (folder) {
^

ReferenceError: folder is not defined