#type error?

52 messages · Page 1 of 1 (latest)

paper fable

can anyone help?

           ^

TypeError: Object.defineProperties called on non-object
    at Function.defineProperties (<anonymous>)
    at copyProps (/Users/xxx/yyy/zzz/node_modules/ts-mixer/dist/cjs/util.js:12:12)
    at SlashCommandBuilder (/Users/xxx/yyy/zzz/node_modules/ts-mixer/dist/cjs/mixins.js:30:34)
    at file:///Users/xxx/yyy/zzz/commands/ping.js:5:11
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v18.16.0```
dense bayBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
paper fable

type error?

dire tartan

Show ping.js line 5 (and possibly the corresponding ping.ts)

paper fable

data: SlashCommandBuilder()

I'm only using js, no ts for now

dire tartan

Then how is there ts-Mixer involvedwaitWhat

Oh wait, it‘s /builders using it, my bad

Can you run npm ls @discordjs/builders please and show the output?

paper fable

zzz@1.0.0 /Users/xxx/yyy/zzz
└─┬ discord.js@14.13.0
└── @discordjs/builders@1.6.5

dire tartan

Show full ping.js and how you run your bot / package.json

paper fable

ping.js

paper fable

most if it is from the guide except im using import

dire tartan

You already showed the code, that looks fine. What about the package.json?

And what command you use to start the bot

paper fable
  "name": "zzz",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "..."
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "..."
  },
  "homepage": "...",
  "dependencies": {
    "chalk": "^5.3.0",
    "discord.js": "^14.13.0",
    "dotenv": "^16.3.1"
  },
  "type": "module"
}

and node .

dire tartan

That makes no sense to me. Can you try reinstalling discord.js and see if that fixes it?

olive scarabBOT

Version 14 has released! Please update at your earliest convenience.

  • Update: npm rm discord.js npm i discord.js
  • Update guide (use CTRL + F to search for the old method or property)
dire tartan

Run the first bullet point 👆

paper fable

Still happens after running both cmds

dire tartan

npm ls -g shows what?

paper fable

/usr/local/lib
├── corepack@0.17.0
├── npm@9.5.1
├── pm2@5.3.0
├── pnpm@8.6.5
├── ts-node@10.9.1
├── typescript@5.1.3
└── update@0.7.4

dire tartan

Do you use pnpm or npm for that bot?

paper fable

npm

dire tartan

Huh, looks all fine to me… one last try: delete node_modules and package-lock.json in your bot folder and npm i again

paper fable

still happens 🥲

dire tartan

Oh wait, I see it now… new SlashCommandBuilder() it‘s a constructor, you‘re missing the new

paper fable

oh you're right

tf i swear i had that

that error is gone now but the bot isn't adding the commands now

[WARNING] The command at /Users/xxx/yyy/zzz/commands/ping.js is missing a required "data" or "execute" property.

dire tartan
paper fable
const __filename = fileURLToPath(import.meta.url);

const __dirname = path.dirname(__filename);


const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const filePath = path.join(commandsPath, file);
    const command = await import(filePath);
    // Set a new item in the Collection with the key as the command name and the value as the exported module
    if ('data' in command && 'execute' in command) {
        client.commands.set(command.data.name, command);
    } else {
        console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
    }
}```

I have to have those two lines at the top otherwise it says something like __dirname isn't defined in ES module scope

(const commandsPath = path.join(__dirname, 'commands');)

dire tartan

You use default export, then you‘d need to (await import(…)).default

just don’t use __dirname and instead use import.meta.url directly

paper fable

const commandsPath = path.join(path.dirname(import.meta.url), 'commands');?

it doesn't like that

dire tartan

Why the path.dirname? ignore me

What about it doesn’t it like?

paper fable

so with just import.meta.url it tries to find a commands folder within the index.js file

So i'm assuming it need to find the directory of where index.js is, then find a commands folder in there

Error: ENOENT: no such file or directory, scandir 'file:/Users/xxx/yyy/discord.js-bot/commands'

when using path.dirname

Not gonna lie that's weird

here's the structure btw

Thanks a lot for the help 🙏, im just gonna leave the fileurltopath in there

How do you close this again