#not a function error

9 messages · Page 1 of 1 (latest)

grave skiff

waves hello! I'm hoping I can get some help. i'm following a tutorial and trying to get this to work but i just... can't figure it out.

require("dotenv").config();
const { token } = process.env;
const { Client, Collection, GatewayIntentBits } = require("discord.js");
const fs = require("fs");

const client = new Client({ intents: GatewayIntentBits.Guilds });
client.commands = new Collection();
client.commandArray = {};

const functionFolders = fs.readdirSync(`./src/functions`);
for (const folder of functionFolders) {
  const functionFiles = fs
    .readdirSync(`./src/functions/${folder}`)
    .filter((file) => file.endsWith(".js"));

  for (const file of functionFiles)
    require(`./functions/${folder}/${file}`)(client);
}

client.handleEvents();
client.handleCommands();
client.login(token);

I'm getting this error:

require(`./functions/${folder}/${file}`)(client);
                                            ^

TypeError: require(...) is not a function
    at Object.<anonymous> (V:\Shattered Realms V4\src\bot.js:17:45)

Any help?

polar helm

show what youre exporting

grave skiff
polar helm

just show me the first line of your module.exports

im not watching a youtube tutorial

grave skiff

two of them are this

module.exports = (client) => {

i hope thats what you mean T^T I'm new to this i'm sorry

twilit galleon

first of all, it’s better to learn how to code a bot from the guide and not from YouTube tutorials as they are often outdated